I need a rule for my Xiaomi temperature and humidity sensor. I need to send notifications to my tg bot when the temperature is greater than 23 degrees. I try to use this:
rule "Xiaomi temp sensor"
when
Channel "mihome:sensor_ht:xxxxxxxxxxxx:temperature" changed from 22.32 to 23.12
then
sendTelegram("bot1", "Temp is changed")
end
but it’s not working ((
EDITED: And how to edit the script so that will sends notifications once an hour or only once ?
Thats because you use the channel.
Use the temperature item. And do it more “correctly” like this:
rule "Xiaomi temp sensor"
when
Item [xiaomi temp sensor item] changed
then
if ([xiaomi temp sensor item] > 23 )
sendTelegram("bot1", "Temp is changed")
end
And, you should pay attention to the logfile as well. I would assume your rule would be triggering errors.
rule "Xiaomi temp sensor"
when
Item [mihome:sensor_ht:xxxxxxxxxxxxxxx:temperature] changed
then
if ([mihome:sensor_ht:xxxxxxxxxxxxxxxx:temperature] > 23 )
sendTelegram("bot1", "Temp is changed")
end
but at the log file:
020-04-30 20:06:02.418 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'telegram.rules' has errors, therefore ignoring it: [3,5]: no viable alternative at input '['
[3,32]: mismatched character 'c' expecting set null
[5,15]: mismatched input ':' expecting ']'
[5,16]: missing ')' at 'sensor_ht'
[5,25]: mismatched input ':' expecting 'end'
[5,30]: mismatched character 'c' expecting set null
Ahh, you need to remove the brackets [ ] I just inserted those so you could see where to put your item.
Like this:
rule "Xiaomi temp sensor"
when
Item mihome:sensor_ht:xxxxxxxxxxxxxxx:temperature changed
then
if (mihome:sensor_ht:xxxxxxxxxxxxxxxx:temperature > 23 )
sendTelegram("bot1", "Temp is changed")
end
cat /etc/openhab2/rules/telegram.rules
rule "Xiaomi temp sensor"
when
Item mihome:sensor_ht:xxxxxxxxxxx:temperature changed
then
if (mihome:sensor_ht:xxxxxxxxxxxxxxxx:temperature > 23 )
sendTelegram("bot1", "Temp is changed")
end
stiil have a error:
2020-04-30 20:41:04.612 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'telegram.rules' has errors, therefore ignoring it: [3,5]: no viable alternative at input ':'
[3,31]: mismatched character 'c' expecting set null
[5,14]: mismatched input ':' expecting ')'
[5,24]: mismatched input ':' expecting 'end'
[5,29]: mismatched character 'c' expecting set null
rule "Xiaomi temp sensor"
when
Item Xi_HT_Temperature changed
then
if ((Xi_HT_Temperature.state as Number) > 23 )
sendTelegram("bot1", "Temp is changed")
end
and in log only:
2020-05-01 00:36:20.698 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'telegram.rules'
You’d want the rule to trigger once an hour, instead of every time the temperature changes.
The magic word is cron trigger
But if the temperature changes to > 23, you might have to wait 59 minutes until the next time the rule runs. Can you say what you want in more detail?
For example -
Want a message as soon as temp > 23
But
Don’t want another message for one hour, and then I want a reminder if temp is still >23.
And
Want a reminder every hour as long as still > 23