i’m trying to track “hot” days and eventually send a notification (or something) when its cool enough outside to open the windows but i’m having trouble storing the prior temperature between temperature changes. i wanted to avoid creating an “item” for it, but is it the only way? here’s my rules so far, the item in question is the “var max = null” seems to always be null at the start of the changed event.
val HOT_DAY_MIN = 82|"°F"
val HOT_DAY_MAX = 78|"°F"
var hotToday = false
var coolNotif = false
var max = null
rule "track hot days"
when
Item zwave_device_831e87fd_node10_sensor_temperature changed
then
var temp = zwave_device_831e87fd_node10_sensor_temperature.state
logInfo("weather", "current temperature is: " + temp);
logInfo("weather", "start: " + temp + ", " + max + ", " + hotToday + ", " + coolNotif)
logInfo("weather", (temp > HOT_DAY_MIN));
logInfo("weather", (hotToday === false));
if (temp > HOT_DAY_MIN && hotToday === false) {
hotToday = true
logInfo("weather", "its hot today! (" + temp + " outside)")
}
if (max === null || temp > max) {
logInfo("weather", "setting new max for today " + temp + ", old value " + max + ", hot " + hotToday)
max = temp
}
if (temp < HOT_DAY_MAX && hotToday === true && coolNotif === false) {
coolNotif = true
logInfo("weather", "its hot today but its cooling now! (" + temp + " outside, max today " + max + ")")
}
logInfo("weather", "end: " + temp + ", " + max + ", " + hotToday + ", " + coolNotif)
end
rule "reset hot days"
when
Time cron "0 0 0 ? * *"
then
hotToday = false
coolNotif = false
max = null
end
actually it seems to work now. i had copy/pasted the syntax for temperature constants from various places (old format vs new) and i switched it from F to C in one of those copy pastes so it was trying to get to 82 celsius
I’m interested in global variables too. My Question:
I want to us a variable over different rule files. So I have to guarantee now, the variables are set first.
Would it work, if I create a 0000_variables.rules File with only the variables in, so it is readed first when openhab2 starts?
Not for the old rule engine, but using the new rule engine, scripted automation, and the helper libraries, you can create variables in modules that can be accessed and changed in any of your scripts. You’d also be getting a head start preparing for OH 3.0. Let me know if you’d like some more details or help in getting things set up.
It’s easier to use than the rules DSL, and there is a way more documentation for Python.
There is no reason to have both, so at some point it will be removed. It’s too soon to tell if that will be OH 3.0. Be aware that the DSL is not the old rule engine, but it’s future is also TBD. There is still a lot to work out yet.
I’m not sure what you mean. The helper library documentation explains everything you need to install things, but it is much easier with the beta Jython bundle, which is the link in the previous post. Soon, it will be available to install through the UI.
Yes, just like when editing .rules files. I use VSCode and the SSH explorer.
Both rule engines can be used at the same time, so testing and migration is very easy to do. If you post a DSL rule, I’ll convert it for you to get you started.
Question 1)
Define in /etc/openhab2/automation/lib/python/configuration.py
or an new /etc/openhab2/automation/jsr232/python/personal/configuration.py ???
I allready tried to define in /etc/openhab2/automation/jsr232/python/personal/000_Init.py
like: ChatID = 12345678 thinking it will readed first and would work, but could to another place too.
Question 2)
Define like
ChatID=“12345678” there like port and host have been in example too?
Question 3)
in rule.py ==> Can you give me a Syntax to import? Thought configuration is allways readed and values can be used everywhere?
For people with more knowledge seems to be stupid questions But I don’t find good overview with google how it works.