HestiaPi has a whole thermostat coded in OH rules. That’s probably going to be a bit overkill though.
I do something similar for my dumb humidifiers though which might be a bit closer to what you need. See below.
Rule conditions are AND only. All the conditions must match for the rule to run. You’ll either need to split this into multiple rules or use a script action to convert it into one rule.
But instead of using a cron trigger, use changes to the current temperature and the temperature. That makes it more responsive.
Approaches you can use to implement this:
-
Use the hysteresis profile on the thermometer channel with a switch channel. Link the channel to a switch Item and set the hysteresis profile with something like 73 for the lower, 75 for the higher and invert to true. This switch will be ON when the AC should be on and off when it’s time to turn it off. The buffer zone (i.e. hysteresis) prevents flapping when the temp is bouncing above and below 75. You’ll have to hard code the thresholds though.
-
Take each of the conditions above and write them as a separate rule using the temperature as the trigger instead of cron. Each rule will be UI only so no coding required. You can use an item instead of hard coding the target temp. You will want to add hysteresis though for the off rules (i.e set to 73 or targetTemp-2 or the like).
-
Use Threshold Alert and Open Reminder [4.0.0.0;4.9.9.9]. This is the approach I use for my humidifiers. In this approach you will install the OHRT library (see link), and install the rule template from the marketplace. Add your thermometer item to a Group. Create a “Script” that will be called to actually turn on and off the AC. You can use Blockly. You’ll turn the AC on when isAlerting is true and off when it’s off. Instantiate the a rule based on the template with the following parameters (if not mentioned leave the parameter at the default).
- triggering group: group created above
- threshold state: 75
- comparison operator: >=
- hysteresis: 2
- alert rule: script created above
- end alert rule: script created above
The threshold alert rule will call your script when the temp reaches or exceeds 75 with isAlerting set to true. It will call it again with isAlerting set to false when it falls below 73.
You have a bunch of other options to play with as you need such as a do not disturb period, an amount of time the temp should be above 75 before you consider it to be alerting, etc.
To get the isAlerting flag in your script, use the “get from context” block in Blockly. In JS Scripting you can just use isAlerting directly. Rules DSL and simple UI rules are not supported and I don’t know how to get it in jRuby.
- Code it yourself. Trigger a rule when the temperature changes. You’ve already ladies out the logic in your bullet points. Using Blockly create and if block and add else if blocks to it (click the cog icon and drag and drop) until you have four. Add a condition to each just as you outline above and send the command that’s appropriate. Again, I recommend hysteresis so use something lower than 75 to turn off.