GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — HumiditySensor/HumiditySensor/module.php at main · Wilkware/HumiditySensor Expand file tree/ Copy pathmodule.phpMore file actions 1857 lines (1699 loc) · 100 KB / Copy pathmodule.phpFile metadata and controls1857 lines (1699 loc) · 100 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 <?php declare(strict_types=1); /** Generell funktions */ require_once __DIR__ . '/../libs/_traits.php'; /** Namespaced traits */ use Wilkware\HumiditySensor\DebugHelper; use Wilkware\HumiditySensor\FormHelper; use Wilkware\HumiditySensor\VariableHelper; use Wilkware\HumiditySensor\VersionHelper; /** * Class HumiditySensor */ class HumiditySensor extends IPSModuleStrict { // ------------------------------------------------------------------------- // Traits // ------------------------------------------------------------------------- use DebugHelper; use FormHelper; use VariableHelper; use VersionHelper; // ------------------------------------------------------------------------- // Constants // ------------------------------------------------------------------------- /** @var int Min IPS Object ID */ private const IPS_MIN_ID = 10000; /** @var string Default sound of push notifications */ private const NOTIFICATION_SOUND = 'turn'; /** @var int Status code for missing climate variables */ private const STATUS_MISSING_VARIABLES = 201; /** @var int Status code for implausible humidity values */ private const STATUS_INVALID_HUMIDITY = 202; /** @var list<string> Properties holding the climate variables */ private const CLIMATE_VARIABLES = [ 'TempOutdoor', 'HumyOutdoor', 'TempIndoor', 'HumyIndoor', ]; /** @var int Update timer value for an event-driven update on changes of the climate variables */ private const UPDATE_ON_CHANGE = 0; /** @var int Delay in seconds after a change to bundle values sent together (e.g. temperature and humidity of one device) */ private const UPDATE_DEBOUNCE = 2; /** @var int Cyclic update in minutes in addition to the event-driven update (season, sensors without changes) */ private const UPDATE_HEARTBEAT = 60; /** @var int Lifetime of the cached history in seconds */ private const HISTORY_CACHE_TIME = 900; /** @var int Season mode: notifications all year round */ private const SEASON_ALWAYS = 0; /** @var int Season mode: heating period determined by the smoothed outdoor temperature */ private const SEASON_AUTOMATIC = 1; /** @var int Season mode: heating period determined by calendar months */ private const SEASON_CALENDAR = 2; /** @var int Hint mode: ventilation dries the room air (climate data only) */ private const HINT_CLIMATE_DATA = 0; /** @var int Hint mode: ventilation required according to the complete ventilation logic (like the notification) */ private const HINT_VENTILATION_LOGIC = 1; /** @var int Clothing mode: fixed clothing insulation */ private const CLOTHING_FIXED = 0; /** @var int Clothing mode: summer/winter clothing switched with the heating period */ private const CLOTHING_AUTOMATIC = 1; /** @var int Clothing mode: interpolated between winter and summer clothing by the smoothed outdoor temperature */ private const CLOTHING_OUTDOOR = 2; /** @var int Thermal state: PMV below the negative limit */ private const THERMAL_COOL = -1; /** @var int Thermal state: PMV within the limits */ private const THERMAL_COMFORTABLE = 0; /** @var int Thermal state: PMV above the positive limit */ private const THERMAL_WARM = 1; /** @var int Time constant for smoothing the outdoor temperature in seconds (48 h, like heating controllers) */ private const SEASON_SMOOTHING = 172800; /** @var float Hysteresis around the heating limit in K (half of the switching difference) */ private const SEASON_HYSTERESIS = 1.0; /** * @var array<int,array{0:string,1:string,2:string,3:int,4:int}> Typical room climate (name, temperature, humidity, upper and lower humidity limit) * Source: https://www.getair.eu/wissen/optimale-luftfeuchtigkeit-so-schuetzen-sie-gesundheit-und-gebaeude/ */ private const ROOM_TYPES = [ 1 => ['Basement', '10 - 15 °C', '50 - 65 %', 65, 50], 2 => ['Hallway', '15 - 18 °C', '40 - 60 %', 60, 40], 3 => ['Kitchen', '18 - 20 °C', '50 - 60 %', 60, 50], 4 => ['Bathroom', '20 - 23 °C', '50 - 70 %', 70, 50], 5 => ['Children\'s room', '20 - 23 °C', '40 - 60 %', 60, 40], 6 => ['Living room', '20 - 23 °C', '40 - 60 %', 60, 40], 7 => ['Study', '20 - 23 °C', '40 - 60 %', 60, 40], 8 => ['Bedroom', '17 - 20 °C', '40 - 60 %', 60, 40], ]; /** @var list<float> Lower limits of the heat index warning levels 1..4 in °C (caution, extreme caution, danger, extreme danger) */ private const HEAT_LEVELS = [27.0, 32.0, 41.0, 54.0]; /** * @var list<string> Comfort index table of the ELV comfort display (rows: 5.0 to 35.9 °C in 0.5 K steps, * columns: 25 to 75 % relative humidity in 1 % steps; 1 = dry, 2 = comfort dry, 3 = comfort ideal, 4 = comfort humid, 5 = humid) */ private const COMFORT_TABLE = [ '111111111111111111222222222222222222223333344444555', // 5.0 - 5.4 °C '111111111111111111222222222222222222223333344444555', // 5.5 - 5.9 °C '111111111111111112222222222222222222233333344444555', // 6.0 - 6.4 °C '111111111111111112222222222222222222233333344444555', // 6.5 - 6.9 °C '111111111111111122222222222222222222333333344444555', // 7.0 - 7.4 °C '111111111111111122222222222222222222333333344444555', // 7.5 - 7.9 °C '111111111111111222222222233333333333333333344444555', // 8.0 - 8.4 °C '111111111111111222222222233333333333333333344444555', // 8.5 - 8.9 °C '111111111111112222222222333333333333333333344444555', // 9.0 - 9.4 °C '111111111111112222222222333333333333333333344444555', // 9.5 - 9.9 °C '111111111111122222222223333333333333333333344444555', // 10.0 - 10.4 °C '111111111111122222222223333333333333333333344444555', // 10.5 - 10.9 °C '111111111111222222222233333333333333333333344444555', // 11.0 - 11.4 °C '111111111111222222222233333333333333333333344444555', // 11.5 - 11.9 °C '111111111112222222222333333333333333333333344444555', // 12.0 - 12.4 °C '111111111112222222222333333333333333333333344444555', // 12.5 - 12.9 °C '111111111122222222223333333333333333333333344444555', // 13.0 - 13.4 °C '111111111122222222223333333333333333333333344444555', // 13.5 - 13.9 °C '111111111222222222233333333333333333333333344444555', // 14.0 - 14.4 °C '111111111222222222233333333333333333333333344444555', // 14.5 - 14.9 °C '111111112222222222333333333333333333333333344444555', // 15.0 - 15.4 °C '111111112222222222333333333333333333333333444445555', // 15.5 - 15.9 °C '111111112222222223333333333333333333333333444445555', // 16.0 - 16.4 °C '111111112222222223333333333333333333333334444455555', // 16.5 - 16.9 °C '111111112222222233333333333333333333333334444455555', // 17.0 - 17.4 °C '111111112222222233333333333333333334444444444555555', // 17.5 - 17.9 °C '111111112222222333333333333333333334444444444555555', // 18.0 - 18.4 °C '111111112222222333333333333333333334444444445555555', // 18.5 - 18.9 °C '111111112222223333333333333333333344444444445555555', // 19.0 - 19.4 °C '111111112222223333333333333333333344444444455555555', // 19.5 - 19.9 °C '111111112222233333333333333333333444444444455555555', // 20.0 - 20.4 °C '111111112222233333333333333333333444444444555555555', // 20.5 - 20.9 °C '111111122222233333333333333333334444444444555555555', // 21.0 - 21.4 °C '111111122222233333333333333333334444444445555555555', // 21.5 - 21.9 °C '111111222222233333333333333333344444444445555555555', // 22.0 - 22.4 °C '111111222222233333333333333333444445555555555555555', // 22.5 - 22.9 °C '111112222222233333333333344444444455555555555555555', // 23.0 - 23.4 °C '111112222222233333333333344444444455555555555555555', // 23.5 - 23.9 °C '111122222222233333333333444444444555555555555555555', // 24.0 - 24.4 °C '111122222222233333333333444444444555555555555555555', // 24.5 - 24.9 °C '111222222222333333333334444444445555555555555555555', // 25.0 - 25.4 °C '111222222222333333333334444444445555555555555555555', // 25.5 - 25.9 °C '111222222223333333333344444444455555555555555555555', // 26.0 - 26.4 °C '111222222223333333333344444444455555555555555555555', // 26.5 - 26.9 °C '111222222233333333333444444444555555555555555555555', // 27.0 - 27.4 °C '111222222233333333333444444444555555555555555555555', // 27.5 - 27.9 °C '111222222233333333334444444445555555555555555555555', // 28.0 - 28.4 °C '111222222333333333334444444445555555555555555555555', // 28.5 - 28.9 °C '111222222333333333344444444455555555555555555555555', // 29.0 - 29.4 °C '111222222333333333344444444455555555555555555555555', // 29.5 - 29.9 °C '111222223333333333444444444555555555555555555555555', // 30.0 - 30.4 °C '111222223333333333444444444555555555555555555555555', // 30.5 - 30.9 °C '111222223333333334444444445555555555555555555555555', // 31.0 - 31.4 °C '111222223333333334444444445555555555555555555555555', // 31.5 - 31.9 °C '111222223333333344444444455555555555555555555555555', // 32.0 - 32.4 °C '111222223333333344444444455555555555555555555555555', // 32.5 - 32.9 °C '111222223333333444444444555555555555555555555555555', // 33.0 - 33.4 °C '111222223333333444444444555555555555555555555555555', // 33.5 - 33.9 °C '111222223333334444444445555555555555555555555555555', // 34.0 - 34.4 °C '111222223333334444444445555555555555555555555555555', // 34.5 - 34.9 °C '111222223333344444444455555555555555555555555555555', // 35.0 - 35.4 °C '111222223333344444444455555555555555555555555555555', // 35.5 - 35.9 °C ]; /** @var string GUID of the archive control module */ private const ARCHIVE_MODULE = '{43192F0B-135B-4CE7-A0A7-1475603F3060}'; /** @var array<string,bool> Tile elements in default order with their default visibility */ private const TILE_ELEMENTS = [ 'Result' => false, 'Outdoor' => true, 'ComfortIndex' => true, 'ThermalComfort' => true, 'HeatIndex' => true, 'Difference' => true, 'DewPoint' => false, 'WaterContent' => false, 'HeatingPeriod' => false, ]; /** @var array<string,array{0:string,1:string}> Caption and description of the tile elements in the configuration form */ private const TILE_CAPTIONS = [ 'Result' => ['Recommendation text', 'Full recommendation text (variable Result) below the indoor values'], 'Outdoor' => ['Outdoor values', 'Outdoor humidity and temperature in the line below the indoor values'], 'ComfortIndex' => ['Room climate index', 'Color scale with marker for the room climate (ELV comfort display)'], 'ThermalComfort' => ['Thermal comfort', 'Color scale with marker for the thermal sensation (PMV) and the dissatisfied (PPD)'], 'HeatIndex' => ['Heat index', 'Color scale with marker for the heat index, only shown from the warning level \'Caution\''], 'Difference' => ['Difference', 'Difference of the water content indoors to outdoors on the right in the line of the outdoor values'], 'DewPoint' => ['Dew point indoor', 'Chip with the dew point of the room air'], 'WaterContent' => ['Water content indoor', 'Chip with the water content of the room air'], 'HeatingPeriod' => ['Season', 'Chip with the season mode (text) and the current heating period (icon)'], ]; /** @var list<int> Tile scale colors of the room climate index 1..5 (as in the presentation) */ private const TILE_COLORS_COMFORT = [16711680, 16750848, 65280, 11579392, 255]; /** @var list<int> Tile scale colors of the thermal sensation from cold to hot (as in the presentation) */ private const TILE_COLORS_PMV = [128, 255, 32960, 5810438, 16776960, 16744448, 16711680]; /** @var list<int> Tile scale colors of the heat warning levels 0..4, -1 = neutral (as in the presentation) */ private const TILE_COLORS_HEAT = [-1, 16776961, 16699191, 16685312, 16646144]; /** @var list<float> Heat index in °C at the borders of the tile scale segments */ private const TILE_HEAT_SCALE = [20.0, 27.0, 32.0, 41.0, 54.0, 60.0]; /** @var int Recommendation: roughly equal humidity indoors and outdoors */ private const RECOMMENDATION_NO_EFFECT = 0; /** @var int Recommendation: ventilation dries the room air */ private const RECOMMENDATION_VENTILATE = 1; /** @var int Recommendation: ventilation dries the room air, but it gets warmer */ private const RECOMMENDATION_WARMER = 2; /** @var int Recommendation: short ventilation possible */ private const RECOMMENDATION_SHORT = 3; /** @var int Recommendation: very short ventilation possible */ private const RECOMMENDATION_VERY_SHORT = 4; /** @var int Recommendation: do not ventilate */ private const RECOMMENDATION_NONE = 5; /** @var array<int,array{0:string,1:int}> Tile badge per recommendation (caption, color) */ private const RECOMMENDATION_BADGES = [ self::RECOMMENDATION_NO_EFFECT => ['No effect', 9342611], self::RECOMMENDATION_VENTILATE => ['Ventilate', 15948332], self::RECOMMENDATION_WARMER => ['Ventilate (warmer)', 15948332], self::RECOMMENDATION_SHORT => ['Ventilate briefly', 15050250], self::RECOMMENDATION_VERY_SHORT => ['Ventilate very briefly', 15050250], self::RECOMMENDATION_NONE => ['Don\'t ventilate', 5810438], ]; /** @var float Universal gas constant in J/(kmol*K) */ private const GAS_CONSTANT = 8314.3; /** @var float Molar mass of water vapour in kg/kmol */ private const MOLAR_MASS_WATER = 18.016; /** @var float Saturation vapour pressure at 0 °C in hPa (Magnus formula) */ private const MAGNUS_BASE = 6.1078; /** @var float Water content difference (g/m³) below which indoor and outdoor air count as equal */ private const EQUAL_WATER_CONTENT = 0.5; /** @var float Increase of the relative humidity (%) up to which ventilation makes it only "a little" more humid */ private const HUMIDITY_INCREASE_LITTLE = 5.0; /** @var float Relative humidity (%) after ventilation up to which short ventilation is fine */ private const HUMIDITY_COMFORT = 55.0; /** @var float Relative humidity (%) after ventilation up to which very short ventilation is acceptable */ private const HUMIDITY_ACCEPTABLE = 65.0; /** @var float Share of the indoor air that remains in the room during ventilation */ private const AIR_EXCHANGE_REMAINING = 0.25; // ------------------------------------------------------------------------- // Presentations // ------------------------------------------------------------------------- /** @var array<string,mixed> Ventilation hint presentation (Value) */ private const THS_PRESENTATION_HINT = [ 'ICON' => 'window-frame', 'OPTIONS' => '[{"Caption":"Don\'t ventilate!","ColorActive":true,"ColorValue":5810438,"ContentColorActive":false,"ContentColorValue":-1,"IconActive":true,"IconValue":"window-frame","Value":false},{"Caption":"Ventilate!","ColorActive":true,"ColorValue":15948332,"ContentColorActive":false,"ContentColorValue":-1,"IconActive":true,"IconValue":"window-frame-open","Value":true}]', 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, ]; /** @var array<string,mixed> Ventilation recommendation presentation (Value), same levels as the tile badge */ private const THS_PRESENTATION_RECOMMENDATION = [ 'ICON' => 'window-frame', 'INTERVALS' => '[{"ColorActive":true,"ColorValue":9342611,"ConstantActive":true,"ConstantValue":"No effect","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"equals","IntervalMaxValue":0,"IntervalMinValue":0,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":15948332,"ConstantActive":true,"ConstantValue":"Ventilate","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"window-frame-open","IntervalMaxValue":1,"IntervalMinValue":1,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":15948332,"ConstantActive":true,"ConstantValue":"Ventilate (warmer)","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"temperature-arrow-up","IntervalMaxValue":2,"IntervalMinValue":2,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":15050250,"ConstantActive":true,"ConstantValue":"Ventilate briefly","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"clock","IntervalMaxValue":3,"IntervalMinValue":3,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":15050250,"ConstantActive":true,"ConstantValue":"Ventilate very briefly","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"stopwatch","IntervalMaxValue":4,"IntervalMinValue":4,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":5810438,"ConstantActive":true,"ConstantValue":"Don\'t ventilate","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"window-frame","IntervalMaxValue":5,"IntervalMinValue":5,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""}]', 'INTERVALS_ACTIVE' => true, 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, ]; /** @var array<string,mixed> Result text presentation (Value) */ private const THS_PRESENTATION_RESULT = [ 'ICON' => 'message-dots', 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, ]; /** @var array<string,mixed> Difference between indoor and outdoor water content presentation (Value) */ private const THS_PRESENTATION_DIFFERENCE = [ 'DIGITS' => 2, 'ICON' => 'plus-minus', 'INTERVALS' => '[{"ColorActive":true,"ColorValue":5810438,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"window-frame","IntervalMaxValue":0,"IntervalMinValue":-100,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":15948332,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"window-frame-open","IntervalMaxValue":100000,"IntervalMinValue":0,"PrefixActive":true,"PrefixValue":"+","SuffixActive":false,"SuffixValue":""}]', 'INTERVALS_ACTIVE' => true, 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, 'SUFFIX' => ' %', ]; /** @var array<string,mixed> Dew point presentation (Value) */ private const THS_PRESENTATION_DEW_POINT = [ 'DIGITS' => 1, 'ICON' => 'temperature-full', 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, 'SUFFIX' => ' °C', 'USAGE_TYPE' => 1, ]; /** @var array<string,mixed> Temperature presentation of the measured values (Value) */ private const THS_PRESENTATION_TEMPERATURE = [ 'DIGITS' => 1, 'ICON' => 'temperature-half', 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, 'SUFFIX' => ' °C', 'USAGE_TYPE' => 1, ]; /** @var array<string,mixed> Relative humidity presentation of the measured values (Value) */ private const THS_PRESENTATION_HUMIDITY = [ 'DIGITS' => 0, 'ICON' => 'droplet', 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, 'SUFFIX' => ' %', ]; /** @var array<string,mixed> Water content presentation (Value) */ private const THS_PRESENTATION_WATER_CONTENT = [ 'COLOR' => 8421504, 'DIGITS' => 2, 'ICON' => 'raindrops', 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, 'SUFFIX' => ' g/m³', ]; /** @var array<string,mixed> Heat index presentation (Value) */ private const THS_PRESENTATION_HEAT_INDEX = [ 'DIGITS' => 1, 'ICON' => 'temperature-high', 'INTERVALS' => '[{"ColorActive":false,"ColorValue":-1,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":1,"IconActive":true,"IconValue":"temperature-half","IntervalMaxValue":26.9,"IntervalMinValue":-100,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16776961,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":1,"IconActive":true,"IconValue":"temperature-three-quarters","IntervalMaxValue":31.9,"IntervalMinValue":27,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16699191,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":1,"IconActive":true,"IconValue":"temperature-full","IntervalMaxValue":40.9,"IntervalMinValue":32,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16685312,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":1,"IconActive":true,"IconValue":"temperature-high","IntervalMaxValue":53.9,"IntervalMinValue":41,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16646144,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":1,"IconActive":true,"IconValue":"triangle-exclamation","IntervalMaxValue":200,"IntervalMinValue":54,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""}]', 'INTERVALS_ACTIVE' => true, 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, 'SUFFIX' => ' °C', 'USAGE_TYPE' => 1, ]; /** @var array<string,mixed> Heat warning level presentation (Value) */ private const THS_PRESENTATION_HEAT_WARNING = [ 'ICON' => 'temperature-high', 'INTERVALS' => '[{"ColorActive":false,"ColorValue":-1,"ConstantActive":true,"ConstantValue":"Harmless","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"temperature-half","IntervalMaxValue":0,"IntervalMinValue":0,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16776961,"ConstantActive":true,"ConstantValue":"Caution","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"temperature-three-quarters","IntervalMaxValue":1,"IntervalMinValue":1,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16699191,"ConstantActive":true,"ConstantValue":"Extreme caution","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"temperature-full","IntervalMaxValue":2,"IntervalMinValue":2,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16685312,"ConstantActive":true,"ConstantValue":"Danger","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"temperature-high","IntervalMaxValue":3,"IntervalMinValue":3,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16646144,"ConstantActive":true,"ConstantValue":"Extreme danger","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"triangle-exclamation","IntervalMaxValue":4,"IntervalMinValue":4,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""}]', 'INTERVALS_ACTIVE' => true, 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, ]; /** @var array<string,mixed> Room climate (comfort) index presentation (Value) */ private const THS_PRESENTATION_COMFORT_INDEX = [ 'ICON' => 'gauge', 'INTERVALS' => '[{"ColorActive":false,"ColorValue":-1,"ConstantActive":true,"ConstantValue":"Out of range","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"circle-question","IntervalMaxValue":0,"IntervalMinValue":0,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16711680,"ConstantActive":true,"ConstantValue":"Dry","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"droplet-slash","IntervalMaxValue":1,"IntervalMinValue":1,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16750848,"ConstantActive":true,"ConstantValue":"Comfort dry","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"droplet","IntervalMaxValue":2,"IntervalMinValue":2,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":65280,"ConstantActive":true,"ConstantValue":"Comfort ideal","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"face-smile","IntervalMaxValue":3,"IntervalMinValue":3,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":11579392,"ConstantActive":true,"ConstantValue":"Comfort humid","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"droplet","IntervalMaxValue":4,"IntervalMinValue":4,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":255,"ConstantActive":true,"ConstantValue":"Humid","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"raindrops","IntervalMaxValue":5,"IntervalMinValue":5,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""}]', 'INTERVALS_ACTIVE' => true, 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, ]; /** @var array<string,mixed> Predicted mean vote presentation (Value) */ private const THS_PRESENTATION_PMV = [ 'ICON' => 'person', 'INTERVALS' => '[{"ColorActive":true,"ColorValue":128,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"snowflake","IntervalMaxValue":-2.51,"IntervalMinValue":-10,"PrefixActive":true,"PrefixValue":"Cold (","SuffixActive":true,"SuffixValue":")"},{"ColorActive":true,"ColorValue":255,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"temperature-low","IntervalMaxValue":-1.51,"IntervalMinValue":-2.5,"PrefixActive":true,"PrefixValue":"Cool (","SuffixActive":true,"SuffixValue":")"},{"ColorActive":true,"ColorValue":32960,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"temperature-quarter","IntervalMaxValue":-0.51,"IntervalMinValue":-1.5,"PrefixActive":true,"PrefixValue":"Slightly cool (","SuffixActive":true,"SuffixValue":")"},{"ColorActive":true,"ColorValue":5810438,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"face-smile","IntervalMaxValue":0.5,"IntervalMinValue":-0.5,"PrefixActive":true,"PrefixValue":"Neutral (","SuffixActive":true,"SuffixValue":")"},{"ColorActive":true,"ColorValue":16776960,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"temperature-three-quarters","IntervalMaxValue":1.5,"IntervalMinValue":0.51,"PrefixActive":true,"PrefixValue":"Slightly warm (","SuffixActive":true,"SuffixValue":")"},{"ColorActive":true,"ColorValue":16744448,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"temperature-high","IntervalMaxValue":2.5,"IntervalMinValue":1.51,"PrefixActive":true,"PrefixValue":"Warm (","SuffixActive":true,"SuffixValue":")"},{"ColorActive":true,"ColorValue":16711680,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"fire","IntervalMaxValue":10,"IntervalMinValue":2.51,"PrefixActive":true,"PrefixValue":"Hot (","SuffixActive":true,"SuffixValue":")"}]', 'INTERVALS_ACTIVE' => true, 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, ]; /** @var array<string,mixed> Predicted percentage of dissatisfied presentation (Value) */ private const THS_PRESENTATION_PPD = [ 'DIGITS' => 1, 'ICON' => 'face-frown', 'INTERVALS' => '[{"ColorActive":true,"ColorValue":5810438,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"face-smile","IntervalMaxValue":5.9,"IntervalMinValue":0,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":9157443,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"face-meh","IntervalMaxValue":9.9,"IntervalMinValue":6,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16776960,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"face-frown","IntervalMaxValue":14.9,"IntervalMinValue":10,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16744448,"ConstantActive":false,"ConstantValue":"","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":2,"IconActive":true,"IconValue":"face-frown","IntervalMaxValue":100,"IntervalMinValue":15,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""}]', 'INTERVALS_ACTIVE' => true, 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, 'SUFFIX' => ' %', ]; /** @var array<string,mixed> Thermal state presentation (Value) */ private const THS_PRESENTATION_THERMAL_STATE = [ 'ICON' => 'person', 'INTERVALS' => '[{"ColorActive":true,"ColorValue":255,"ConstantActive":true,"ConstantValue":"Too cool","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"temperature-low","IntervalMaxValue":-1,"IntervalMinValue":-1,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":5810438,"ConstantActive":true,"ConstantValue":"Comfortable","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"face-smile","IntervalMaxValue":0,"IntervalMinValue":0,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""},{"ColorActive":true,"ColorValue":16744448,"ConstantActive":true,"ConstantValue":"Too warm","ContentColorActive":false,"ContentColorValue":-1,"ConversionFactor":1,"DigitsActive":false,"DigitsValue":0,"IconActive":true,"IconValue":"temperature-high","IntervalMaxValue":1,"IntervalMinValue":1,"PrefixActive":false,"PrefixValue":"","SuffixActive":false,"SuffixValue":""}]', 'INTERVALS_ACTIVE' => true, 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, ]; /** @var array<string,mixed> Heating period presentation (Value) */ private const THS_PRESENTATION_HEATING_PERIOD = [ 'ICON' => 'fire-flame-curved', 'OPTIONS' => '[{"Caption":"Outside heating period","ColorActive":false,"ColorValue":-1,"ContentColorActive":false,"ContentColorValue":-1,"IconActive":true,"IconValue":"sun","Value":false},{"Caption":"Heating period","ColorActive":false,"ColorValue":-1,"ContentColorActive":false,"ContentColorValue":-1,"IconActive":true,"IconValue":"fire-flame-curved","Value":true}]', 'PRESENTATION' => VARIABLE_PRESENTATION_VALUE_PRESENTATION, ]; // ------------------------------------------------------------------------- // Methods // ------------------------------------------------------------------------- /** * In contrast to Construct, this function is called only once when creating the instance and starting Symcon. * Therefore, status variables and module properties which the module requires permanently should be created here. * * @return void */ public function Create(): void { //Never delete this line! parent::Create(); // Outdoor climate $this->RegisterPropertyInteger('TempOutdoor', 0); $this->RegisterPropertyInteger('HumyOutdoor', 0); // Indoor climate $this->RegisterPropertyInteger('TempIndoor', 0); $this->RegisterPropertyInteger('HumyIndoor', 0); // Thermal comfort $this->RegisterPropertyInteger('ClothingMode', self::CLOTHING_FIXED); $this->RegisterPropertyFloat('Clothing', 0.7); $this->RegisterPropertyFloat('ClothingSummer', 0.5); $this->RegisterPropertyFloat('ClothingWinter', 1.0); $this->RegisterPropertyFloat('ClothingTempWinter', 5.0); $this->RegisterPropertyFloat('ClothingTempSummer', 20.0); $this->RegisterPropertyFloat('Activity', 1.2); $this->RegisterPropertyFloat('AirVelocity', 0.1); $this->RegisterPropertyInteger('TempRadiant', 0); $this->RegisterPropertyFloat('ThermalLimitUpper', 0.5); $this->RegisterPropertyFloat('ThermalLimitLower', -0.5); $this->RegisterPropertyFloat('ThermalHysteresis', 0.2); // Message management $this->RegisterPropertyInteger('DashboardMessage', 0); $this->RegisterPropertyInteger('NotificationMessage', 0); $this->RegisterPropertyInteger('InstanceWebfront', 0); $this->RegisterPropertyString('NotificationSound', self::NOTIFICATION_SOUND); $this->RegisterPropertyInteger('ScriptMessage', 0); $this->RegisterPropertyString('MessageKey', ''); $this->RegisterPropertyString('RoomName', 'Unknown'); $this->RegisterPropertyInteger('LifeTime', 0); $this->RegisterPropertyInteger('NotificationPause', 30); // Ventilation logic $this->RegisterPropertyInteger('UpdateTimer', self::UPDATE_ON_CHANGE); $this->RegisterPropertyInteger('HintMode', self::HINT_CLIMATE_DATA); $this->RegisterPropertyInteger('SeasonMode', self::SEASON_ALWAYS); $this->RegisterPropertyFloat('HeatingLimit', 15.0); $this->RegisterPropertyInteger('SeasonStart', 10); $this->RegisterPropertyInteger('SeasonEnd', 4); $this->RegisterPropertyBoolean('CreateHeatingPeriod', false); $this->RegisterPropertyInteger('RoomType', 0); $this->RegisterPropertyInteger('MinHumidity', 60); $this->RegisterPropertyFloat('MinDifference', 1.0); $this->RegisterPropertyInteger('WindowContact', 0); // Visualisation $this->RegisterPropertyBoolean('ShowRoom', true); $this->RegisterPropertyString('TileElements', '[]'); $this->RegisterPropertyInteger('ChartMode', 1); $this->RegisterPropertyInteger('ChartPeriod', 24); $this->RegisterPropertyBoolean('ChartBand', true); $this->RegisterPropertyInteger('ChartColor', -1); $this->RegisterPropertyInteger('ChartColorTemp', -1); // Advanced settings $this->RegisterPropertyBoolean('CreateDewPoint', true); $this->RegisterPropertyBoolean('CreateWaterContent', true); $this->RegisterPropertyBoolean('CreateOutdoorValues', true); $this->RegisterPropertyBoolean('CreateMeasuredIndoor', false); $this->RegisterPropertyBoolean('CreateMeasuredOutdoor', false); $this->RegisterPropertyBoolean('CreateHeatIndex', false); $this->RegisterPropertyBoolean('CreateComfortIndex', false); $this->RegisterPropertyBoolean('CreateThermalComfort', false); $this->RegisterPropertyBoolean('CreateThermalState', false); // Deprecated: replaced by the ventilation logic, only an existing variable is still evaluated $this->RegisterPropertyInteger('MessageThreshold', 100); $this->RegisterPropertyBoolean('CreateThreshold', false); // Smoothed outdoor temperature and heating period state $this->RegisterAttributeString('SeasonState', '{}'); // Notification already sent for the current ventilation phase (survives restarts) $this->RegisterAttributeBoolean('Notified', false); // Time of the last push notification (minimum pause between notifications) $this->RegisterAttributeInteger('NotificationTime', 0); // Dashboard message of the current ventilation phase (number, expiry and text), removed when the phase ends $this->RegisterAttributeString('DashboardEntry', '{}'); // Last determined heating period (tile chip, also without the variable) $this->RegisterAttributeBoolean('HeatingPeriod', false); // Update timer $this->RegisterTimer('UpdateTrigger', 0, "THS_Update(\$_IPS['TARGET']);"); // Set visualization type to 1, as we want to offer HTML $this->SetVisualizationType(1); // Wait for the kernel before accessing foreign variables $this->RegisterMessage(0, IPS_KERNELSTARTED); } /** * Migrate the persistence of existing instances after a module update. * The symmetric thermal limit is split into an upper and a lower limit. * Existing instances keep the former defaults of the update timer (15 min) and the notification pause (none). * * @param string $json Persistence (configuration and attributes) of the instance * * @return string New persistence, empty if nothing has changed */ public function Migrate(string $json): string { parent::Migrate($json); $data = json_decode($json); if (!isset($data->configuration)) { return ''; } $changed = false; if (isset($data->configuration->ThermalLimit)) { $limit = abs((float) $data->configuration->ThermalLimit); $data->configuration->ThermalLimitUpper = $limit; $data->configuration->ThermalLimitLower = -$limit; unset($data->configuration->ThermalLimit); $changed = true; } if (!isset($data->configuration->NotificationPause)) { if (!isset($data->configuration->UpdateTimer)) { $data->configuration->UpdateTimer = 15; } $data->configuration->NotificationPause = 0; $changed = true; } return $changed ? json_encode($data) : ''; } /** * The content can be overwritten in order to transfer a self-created configuration page. * This way, content can be generated dynamically. * In this case, the "form.json" on the file system is completely ignored. * * @return string Content of the configuration page. */ public function GetConfigurationForm(): string { // Get form $form = json_decode(file_get_contents(__DIR__ . '/form.json'), true); // Extract version $ins = IPS_GetInstance($this->InstanceID); $mod = IPS_GetModule($ins['ModuleInfo']['ModuleID']); $lib = IPS_GetLibrary($mod['LibraryID']); $version = sprintf('v%s.%d', $lib['Version'], $lib['Build']); $this->ModifyFormElement($form['actions'], 'Version', function (array &$element) use ($version): void { $element['caption'] = $version; }); // Show only the settings of the selected season and clothing mode and of the thermal state $this->UpdateFormVisibility($this->ReadPropertyInteger('SeasonMode'), $this->ReadPropertyInteger('ClothingMode'), $this->ReadPropertyBoolean('CreateThermalState'), $form['elements']); // Typical room climate $rooms = []; foreach (self::ROOM_TYPES as $room) { $rooms[] = ['Room' => $this->Translate($room[0]), 'Temperature' => $room[1], 'Humidity' => $room[2]]; } $this->ModifyFormElement($form['elements'], 'RoomTable', function (array &$element) use ($rooms): void { $element['values'] = $rooms; }); // Tile elements with translated captions in the configured order $elements = []; foreach ($this->ReadTileElements() as $ident => $show) { $elements[] = [ 'Show' => $show, 'Name' => $this->Translate(self::TILE_CAPTIONS[$ident][0]), 'Description' => $this->Translate(self::TILE_CAPTIONS[$ident][1]), 'Ident' => $ident, ]; } $this->ModifyFormElement($form['elements'], 'TileElements', function (array &$element) use ($elements): void { $element['values'] = $elements; }); return json_encode($form); } /** * Is executed when "Apply" is pressed on the configuration page and immediately after the instance has been created. * * @return void */ public function ApplyChanges(): void { //Never delete this line! parent::ApplyChanges(); // Result, hint & difference $hint = $this->TranslatePresentation(self::THS_PRESENTATION_HINT, 'OPTIONS', 'Caption'); $recommendation = $this->TranslatePresentation(self::THS_PRESENTATION_RECOMMENDATION, 'INTERVALS', 'ConstantValue'); $this->MaintainVariable('Recommendation', $this->Translate('Recommendation'), VARIABLETYPE_INTEGER, $recommendation, 3, true); $this->MaintainVariable('Hint', $this->Translate('Hint'), VARIABLETYPE_BOOLEAN, $hint, 1, true); $this->MaintainVariable('Result', $this->Translate('Result'), VARIABLETYPE_STRING, self::THS_PRESENTATION_RESULT, 2, true); $this->MaintainVariable('Difference', $this->Translate('Difference'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_DIFFERENCE, 3, true); $outdoor = $this->ReadPropertyBoolean('CreateOutdoorValues'); // Dew point $create = $this->ReadPropertyBoolean('CreateDewPoint'); $this->MaintainVariable('DewPointOutdoor', $this->Translate('Dew point outdoor'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_DEW_POINT, 4, $create && $outdoor); $this->MaintainVariable('DewPointIndoor', $this->Translate('Dew point indoor'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_DEW_POINT, 5, $create); // Water content $create = $this->ReadPropertyBoolean('CreateWaterContent'); $this->MaintainVariable('WaterContentOutdoor', $this->Translate('Water content outdoor'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_WATER_CONTENT, 6, $create && $outdoor); $this->MaintainVariable('WaterContentIndoor', $this->Translate('Water content indoor'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_WATER_CONTENT, 7, $create); // Deprecated message threshold, an existing variable is kept (no loss of archive data) but no longer created if ($this->HasThresholdVariable()) { $this->EnableAction('MessageThreshold'); } // Heating period $create = $this->ReadPropertyBoolean('CreateHeatingPeriod') && ($this->ReadPropertyInteger('SeasonMode') !== self::SEASON_ALWAYS); $heating = $this->TranslatePresentation(self::THS_PRESENTATION_HEATING_PERIOD, 'OPTIONS', 'Caption'); $this->MaintainVariable('HeatingPeriod', $this->Translate('Heating period'), VARIABLETYPE_BOOLEAN, $heating, 9, $create); // Heat index $create = $this->ReadPropertyBoolean('CreateHeatIndex'); $warning = $this->TranslatePresentation(self::THS_PRESENTATION_HEAT_WARNING, 'INTERVALS', 'ConstantValue'); $this->MaintainVariable('HeatIndex', $this->Translate('Heat index'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_HEAT_INDEX, 10, $create); $this->MaintainVariable('HeatWarning', $this->Translate('Heat warning'), VARIABLETYPE_INTEGER, $warning, 11, $create); // Room climate (comfort) index $create = $this->ReadPropertyBoolean('CreateComfortIndex'); $comfort = $this->TranslatePresentation(self::THS_PRESENTATION_COMFORT_INDEX, 'INTERVALS', 'ConstantValue'); $this->MaintainVariable('ComfortIndex', $this->Translate('Room climate index'), VARIABLETYPE_INTEGER, $comfort, 12, $create); // Thermal comfort (PMV/PPD) $create = $this->ReadPropertyBoolean('CreateThermalComfort'); $pmv = $this->TranslatePresentation(self::THS_PRESENTATION_PMV, 'INTERVALS', 'PrefixValue'); $this->MaintainVariable('PredictedMeanVote', $this->Translate('Thermal comfort (PMV)'), VARIABLETYPE_FLOAT, $pmv, 13, $create); $this->MaintainVariable('PredictedDissatisfied', $this->Translate('Dissatisfied (PPD)'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_PPD, 14, $create); $create = $create && $this->ReadPropertyBoolean('CreateThermalState'); $state = $this->TranslatePresentation(self::THS_PRESENTATION_THERMAL_STATE, 'INTERVALS', 'ConstantValue'); $this->MaintainVariable('ThermalState', $this->Translate('Thermal state'), VARIABLETYPE_INTEGER, $state, 15, $create); // Copy of the measured values used for the last calculation $create = $this->ReadPropertyBoolean('CreateMeasuredIndoor'); $this->MaintainVariable('TemperatureIndoor', $this->Translate('Indoor temperature'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_TEMPERATURE, 16, $create); $this->MaintainVariable('HumidityIndoor', $this->Translate('Indoor humidity'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_HUMIDITY, 17, $create); $create = $this->ReadPropertyBoolean('CreateMeasuredOutdoor'); $this->MaintainVariable('TemperatureOutdoor', $this->Translate('Outdoor temperature'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_TEMPERATURE, 18, $create); $this->MaintainVariable('HumidityOutdoor', $this->Translate('Outdoor humidity'), VARIABLETYPE_FLOAT, self::THS_PRESENTATION_HUMIDITY, 19, $create); // Settings may have changed the history $this->SetBuffer('History', ''); // Foreign variables may not be available yet, ApplyChanges is called again on IPS_KERNELSTARTED if (IPS_GetKernelRunlevel() !== KR_READY) { return; } // Event-driven update: (re)register the changes of the climate variables foreach ($this->GetMessageList() as $senderID => $messages) { if (in_array(VM_UPDATE, $messages, true)) { $this->UnregisterMessage($senderID, VM_UPDATE); } } if ($this->ReadPropertyInteger('UpdateTimer') === self::UPDATE_ON_CHANGE) { foreach ([...self::CLIMATE_VARIABLES, 'TempRadiant'] as $property) { $variable = $this->ReadPropertyInteger($property); if ($this->IsValidVariable($variable)) { $this->RegisterMessage($variable, VM_UPDATE); } } } // Opening or closing the window updates the notification at once, also with a cyclic update $window = $this->ReadPropertyInteger('WindowContact'); if ($this->IsValidVariable($window)) { $this->RegisterMessage($window, VM_UPDATE); } // Delete all references in order to readd them foreach ($this->GetReferenceList() as $referenceID) { $this->UnregisterReference($referenceID); } // Register references foreach (self::CLIMATE_VARIABLES as $property) { $variable = $this->ReadPropertyInteger($property); if ($this->IsValidVariable($variable)) { $this->RegisterReference($variable); } } foreach (['TempRadiant', 'WindowContact'] as $property) { $variable = $this->ReadPropertyInteger($property); if ($this->IsValidVariable($variable)) { $this->RegisterReference($variable); } } foreach (['InstanceWebfront', 'ScriptMessage'] as $property) { $object = $this->ReadPropertyInteger($property); if ($object >= self::IPS_MIN_ID && IPS_ObjectExists($object)) { $this->RegisterReference($object); } } // Check configuration if (!$this->HasClimateVariables()) { $this->SetTimerInterval('UpdateTrigger', 0); $this->SetStatus(self::STATUS_MISSING_VARIABLES); $this->UpdateVisualizationValue($this->GetFullUpdateMessage()); return; } $this->SetStatus(102); // Calculate immediately with the new settings $this->Update(); } /** * The content of the function can be overwritten in order to carry out own reactions to certain messages. * The function is only called for registered MessageIDs/SenderIDs combinations. * * data[0] = new value * data[1] = value changed? * data[2] = old value * data[3] = timestamp. * * @param int $timestamp Continuous counter timestamp * @param int $sender Sender ID * @param int $message ID of the message * @param array{0:mixed,1:bool,2:mixed,3:int} $data Data of the message * * @return void */ public function MessageSink(int $timestamp, int $sender, int $message, array $data): void { if ($message === IPS_KERNELSTARTED) { $this->ApplyChanges(); } // Values sent together trigger only one calculation, each further change restarts the delay if ($message === VM_UPDATE && $data[1]) { $this->SetTimerInterval('UpdateTrigger', 1000 * self::UPDATE_DEBOUNCE); } } /** * Is called when, for example, a button is clicked in the visualization. * * @param string $ident Ident of the variable * @param mixed $value The value to be set * * @return void */ public function RequestAction(string $ident, mixed $value): void { // Debug output $this->LogDebug(__FUNCTION__, $ident . ' => ' . $this->Stringify($value)); switch ($ident) { case 'MessageThreshold': $this->SetValueInteger($ident, (int) $value); break; case 'OnFormVisibility': // Season mode, clothing mode and thermal state as JSON array $modes = json_decode((string) $value, true); $this->UpdateFormVisibility((int) ($modes[0] ?? 0), (int) ($modes[1] ?? 0), (bool) ($modes[2] ?? false)); break; case 'OnRoomType': $value = (int) $value; if (isset(self::ROOM_TYPES[$value])) { $this->UpdateFormField('MinHumidity', 'value', self::ROOM_TYPES[$value][3]); } break; default: $this->LogDebug(__FUNCTION__, 'There was no reaction to the action.'); } } /** * If the HTML-SDK is to be used, this function must be overwritten in order to return the HTML content. * * @return string Initial display of a representation via HTML SDK */ public function GetVisualizationTile(): string { // Add a script to set the values when loading, analogous to changes at runtime // Although the return from GetFullUpdateMessage is already JSON-encoded, json_encode is still executed a second time // This adds quotation marks to the string and any quotation marks within it are escaped correctly $handling = '<script>handleMessage(' . json_encode($this->GetFullUpdateMessage()) . ');</script>'; // Add static HTML from file $module = file_get_contents(__DIR__ . '/module.html'); // Important: $handling at the end, as the handleMessage function is only defined in the HTML return $module . $handling; } /** * This function will be available automatically after the module is imported with the module control. * Using the custom prefix this function will be callable from PHP and JSON-RPC through:. * * THS_Update($id); * * @return void */ public function Update(): void { // Back to the cyclic interval (also after the delay of the event-driven update) $minutes = $this->ReadPropertyInteger('UpdateTimer'); $this->SetTimerInterval('UpdateTrigger', 1000 * 60 * ($minutes === self::UPDATE_ON_CHANGE ? self::UPDATE_HEARTBEAT : $minutes)); // Read climate data $tempOutdoor = $this->ReadClimateValue('TempOutdoor', false); $humyOutdoor = $this->ReadClimateValue('HumyOutdoor', true); $tempIndoor = $this->ReadClimateValue('TempIndoor', false); $humyIndoor = $this->ReadClimateValue('HumyIndoor', true); $this->LogDebug(__FUNCTION__, sprintf('Outdoor (t/h): %s / %s', $this->Stringify($tempOutdoor), $this->Stringify($humyOutdoor))); $this->LogDebug(__FUNCTION__, sprintf('Indoor (t/h): %s / %s', $this->Stringify($tempIndoor), $this->Stringify($humyIndoor))); // All values available? if ($tempOutdoor === null || $humyOutdoor === null || $tempIndoor === null || $humyIndoor === null) { $this->SetValueString('Result', $this->Translate('Result could not be determined!')); $this->SetStatus(self::STATUS_MISSING_VARIABLES); $this->UpdateVisualizationValue($this->GetFullUpdateMessage()); return; } // A humidity of 0% would lead to an infinite dew point and a division by zero if ($humyOutdoor <= 0 || $humyOutdoor > 100 || $humyIndoor <= 0 || $humyIndoor > 100) { $this->LogDebug(__FUNCTION__, 'Humidity out of range (0 < h <= 100)!'); $this->SetValueString('Result', $this->Translate('Result could not be determined!')); $this->SetStatus(self::STATUS_INVALID_HUMIDITY); $this->UpdateVisualizationValue($this->GetFullUpdateMessage()); return; } $this->SetStatus(102); // Copy of the measured values if ($this->ReadPropertyBoolean('CreateMeasuredIndoor')) { $this->SetValueFloat('TemperatureIndoor', $tempIndoor); $this->SetValueFloat('HumidityIndoor', $humyIndoor); } if ($this->ReadPropertyBoolean('CreateMeasuredOutdoor')) { $this->SetValueFloat('TemperatureOutdoor', $tempOutdoor); $this->SetValueFloat('HumidityOutdoor', $humyOutdoor); } // Vapour pressure in hPa $outdoor = $this->ReadPropertyBoolean('CreateOutdoorValues'); $saturationOutdoor = $this->SaturationVapourPressure($tempOutdoor); $saturationIndoor = $this->SaturationVapourPressure($tempIndoor); $vapourOutdoor = $humyOutdoor / 100 * $saturationOutdoor; $vapourIndoor = $humyIndoor / 100 * $saturationIndoor; // Dew point if ($this->ReadPropertyBoolean('CreateDewPoint')) { if ($outdoor) { $this->SetValueFloat('DewPointOutdoor', $this->DewPoint($tempOutdoor, $vapourOutdoor)); } $this->SetValueFloat('DewPointIndoor', $this->DewPoint($tempIndoor, $vapourIndoor)); } // Water content (absolute humidity) $waterOutdoor = $this->WaterContent($tempOutdoor, $vapourOutdoor); $waterIndoor = $this->WaterContent($tempIndoor, $vapourIndoor); $this->LogDebug(__FUNCTION__, sprintf('Water content (i/o): %.2f / %.2f g/m³', $waterIndoor, $waterOutdoor)); if ($this->ReadPropertyBoolean('CreateWaterContent')) { if ($outdoor) { $this->SetValueFloat('WaterContentOutdoor', $waterOutdoor); } $this->SetValueFloat('WaterContentIndoor', $waterIndoor); } // Heat index (perceived temperature indoors) if ($this->ReadPropertyBoolean('CreateHeatIndex')) { $heatIndex = $this->HeatIndex($tempIndoor, $humyIndoor); $this->LogDebug(__FUNCTION__, sprintf('Heat index: %.1f °C', $heatIndex)); $this->SetValueFloat('HeatIndex', $heatIndex); $this->SetValueInteger('HeatWarning', $this->HeatWarningLevel($heatIndex)); } // Room climate (comfort) index if ($this->ReadPropertyBoolean('CreateComfortIndex')) { $comfortIndex = $this->ComfortIndex($tempIndoor, $humyIndoor); $this->LogDebug(__FUNCTION__, sprintf('Room climate index: %d', $comfortIndex)); $this->SetValueInteger('ComfortIndex', $comfortIndex); } // Heating period (season for notifications and automatic clothing) $heating = $this->IsHeatingPeriod($tempOutdoor); // Thermal comfort (PMV/PPD) if ($this->ReadPropertyBoolean('CreateThermalComfort')) { $radiant = $this->ReadClimateValue('TempRadiant', false) ?? $tempIndoor; $clothing = $this->ClothingInsulation($heating); $this->LogDebug(__FUNCTION__, sprintf('Clothing: %.2f clo', $clothing)); $comfort = $this->ThermalComfort($tempIndoor, $radiant, $humyIndoor, $clothing); if ($comfort === null) { $this->LogDebug(__FUNCTION__, 'PMV calculation did not converge!'); } else { $this->LogDebug(__FUNCTION__, sprintf('PMV: %.2f, PPD: %.1f%%', $comfort[0], $comfort[1])); $this->SetValueFloat('PredictedMeanVote', $comfort[0]); $this->SetValueFloat('PredictedDissatisfied', $comfort[1]); if ($this->ReadPropertyBoolean('CreateThermalState')) { $this->SetValueInteger('ThermalState', $this->ThermalState($comfort[0], $this->GetValue('ThermalState'))); } } } // Difference: how much more water the indoor air contains compared to the outdoor air $difference = round(($waterIndoor / $waterOutdoor * 100) - 100, 2); $this->SetValueFloat('Difference', $difference); // Outdoor air heated to indoor temperature keeps its vapour pressure $humyOutdoorHeated = $vapourOutdoor / $saturationIndoor * 100; $this->LogDebug(__FUNCTION__, sprintf('Outdoor air at indoor temperature: %.0f%%', $humyOutdoorHeated)); $humyAfter = round(self::AIR_EXCHANGE_REMAINING * $humyIndoor + (1 - self::AIR_EXCHANGE_REMAINING) * $humyOutdoorHeated, 0); $this->LogDebug(__FUNCTION__, sprintf('Indoor humidity after ventilation: %.0f%%', $humyAfter)); // Recommendation $amount = ($humyAfter - $humyIndoor) <= self::HUMIDITY_INCREASE_LITTLE ? $this->Translate('a little') : $this->Translate('much'); if (abs($waterIndoor - $waterOutdoor) <= self::EQUAL_WATER_CONTENT) { $hint = false; $recommendation = self::RECOMMENDATION_NO_EFFECT; $result = $this->Translate('Roughly equal humidity indoors and outdoors!'); } elseif ($waterIndoor > $waterOutdoor && $tempIndoor > $tempOutdoor) { $hint = true; $recommendation = self::RECOMMENDATION_VENTILATE; $result = $this->Translate('Ventilate!!'); } elseif ($waterIndoor > $waterOutdoor) { $hint = true; $recommendation = self::RECOMMENDATION_WARMER; $result = $this->Translate('Ventilation possible, but it will get warmer!!'); } elseif ($humyAfter <= self::HUMIDITY_COMFORT) { // The comfort range of the relative humidity is between 45% and 55% $hint = true; $recommendation = self::RECOMMENDATION_SHORT; $result = sprintf($this->Translate('Short ventilation possible, but it will get %s more humid (up to 50-60%% is OK)'), $amount); } elseif ($humyAfter <= self::HUMIDITY_ACCEPTABLE) { $hint = true; $recommendation = self::RECOMMENDATION_VERY_SHORT; $result = sprintf($this->Translate('Very short ventilation possible, but it will get %s more humid (up to 60%% still acceptable)'), $amount); } else { $hint = false; $recommendation = self::RECOMMENDATION_NONE; $result = $this->Translate('Do NOT ventilate!'); } $this->SetValueInteger('Recommendation', $recommendation); $this->LogDebug(__FUNCTION__, $result); $this->SetValueString('Result', $result); // Season $season = ($this->ReadPropertyInteger('SeasonMode') === self::SEASON_ALWAYS) || $heating; // Notify only if ventilation really dries the room air and the room air is too humid $notify = $hint && $season && ($waterIndoor > $waterOutdoor); $minDifference = $this->ReadPropertyFloat('MinDifference'); if ($minDifference > 0 && ($waterIndoor - $waterOutdoor) < $minDifference) { $notify = false; } $minHumidity = $this->ReadPropertyInteger('MinHumidity'); if ($minHumidity > 0 && $humyIndoor < $minHumidity) { $notify = false; } if ($this->HasThresholdVariable() && $difference <= $this->GetValue('MessageThreshold')) { $notify = false; } $this->LogDebug(__FUNCTION__, sprintf('Notify: %s (season: %s)', $this->Stringify($notify), $this->Stringify($season))); // The hint follows the climate data or optionally the complete ventilation logic (trigger for automations) $this->SetValueBoolean('Hint', $this->ReadPropertyInteger('HintMode') === self::HINT_VENTILATION_LOGIC ? $notify : $hint); // An open window already ventilates, only the notification is suppressed (the hint may control the window itself) // Closing the window while the conditions are still met starts a new ventilation phase if ($notify && $this->IsWindowOpen()) { $this->LogDebug(__FUNCTION__, 'Window open, notification suppressed'); $notify = false; } // Notify only once each time the conditions are met, the dashboard message follows the recommendation // and disappears when the conditions no longer apply if ($notify && !$this->ReadAttributeBoolean('Notified')) { // Conditions flapping around a limit must not push a notification each time $pause = $this->ReadPropertyInteger('NotificationPause') * 60; $push = (time() - $this->ReadAttributeInteger('NotificationTime')) >= $pause; $this->LogDebug(__FUNCTION__, sprintf('Push notification: %s (pause: %d min)', $this->Stringify($push), $pause / 60)); $this->SendMessages($result, $push); } elseif ($notify) { $this->ReplaceDashboardMessage($result); } else { $this->RemoveDashboardMessage(); } $this->WriteAttributeBoolean('Notified', $notify); // Update the tile $this->UpdateVisualizationValue($this->GetFullUpdateMessage()); } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |