I am completely new to OpenHab and having some great fun with it. I’ve managed to get my Z Wave network up and running and have followed the getting started tutorials on the OpenHab website. Ive also got myOpenHab up and running and I was able to follow a tutorial sending push notifications to my mobile phone and also by SMS when you toggle a switch via the Basic UI. Great!!
Ive got it showing up on OpenHab ok and I can see the status as being online.
I am trying to now create a simple rule with notifications.rules so that when the smoke detector goes off or I press the test button I merely need a notification to be sent either to my phone or mail.
I can’t seem to get it to work and its really starting to bug me. I have gone through similar examples based on this. If anyone could kindly help my sanity I would be very grateful for your help.
In my notifications.rules I have this which was modified from the example I had working above so I know that notifications definitely do work ok but something isn’t right here as when I press the smoke alarm test button I don’t get a notification.
rule "Fire in Office"
when
Item zwave_device_7763853a_node6_alarm_smoke changed
then
if(zwave_device_7763853a_node6_alarm_smoke.state == ON)
{
logInfo("notifications", "Smoke Detected in Office")
sendNotification("xxxxxxxx@gmail.com", "Smoke Detected in Office")
}
end
The item you showed us seems not to be linked to a channel ( although you could have done that via PaperUI). If the item is not linked it will never change its state!
A logInfo line before the if statement would show if the rule is triggered at all.
yes I set the link via PaperUI and when I unlinked and relinked it I can see that happening in the logs.
I placed the log info before the if statement so it now shows as:
rule "Fire in Office"
when
Item zwave_device_7763853a_node6_alarm_smoke changed
then
logInfo("notifications", "Smoke Detected in Office")
sendNotification("xxxxxxxx@gmail.com", "Smoke Detected in Office")
if(zwave_device_7763853a_node6_alarm_smoke.state == ON)
{
logInfo("notifications", "Smoke Detected in Office")
sendNotification("xxxxxxxx@gmail.com", "Smoke Detected in Office")
}
end
Sadly not seeing anything generated in the logs nor via notification in myOpenHab
Based on the code above that should work ok? (in theory)
If it’s the channel then change the rule from Item to Channel
rule "Fire in Office"
when
Channel zwave_device_7763853a_node6_alarm_smoke triggered ON
then
logInfo("notifications", "Smoke Detected in Office")
sendNotification("xxxxxxxx@gmail.com", "Smoke Detected in Office")
if(zwave_device_7763853a_node6_alarm_smoke.state == ON)
{
logInfo("notifications", "Smoke Detected in Office")
sendNotification("xxxxxxxx@gmail.com", "Smoke Detected in Office")
}
end
EDIT:
N/M I see above you have the item posted as:
This item has no channel defined so please add it by copying the correct syntax from paperUI and also unlink it in paperui if you are going to use a file for items. Once you add the channel to the item file and save, the link should automatically happen.
OK tried your suggestions above and sadly still no luck. This is the how I see the device via Paper UI --> Things. First I tried the Alarm (smoke) is set as a channel enabled. I also tried disabling this channel via PaperUI and writing the switch line within notifications.items. Note: I added the <switch> tag at the end as it was missing from your line above?
rule "Fire in Office"
when
Item Alarm changed to ON
then
logInfo("notifications", "Smoke Detected in Office")
sendNotification("xxxxxxxx@gmail.com", "Smoke Detected in Office")
end
You can use the channel as a trigger. Mostly see this with the Astro binding.
Example:
rule "AqaraWirelessSwitch2Go"
when
Channel "deconz:switch:homeserver:00158d0001e83c05010006:buttonevent" triggered
then
logInfo("AqaraWirelessSwitch2Go", "AqaraWirelessSwitch2Go wurde gedrückt")
// Assume current dim is 0 if Item is NULL, light will turn on at 20%
val curr = if(Licht_Buero_Deckenfluter.state === NULL) 0 else Licht_Buero_Deckenfluter.state as Number
val newDim = curr + 20 // calculate the new dim value
val newState = if(newDim <= 100) ON else OFF // determine if the light should be ON or OFF
if(newState == OFF) Licht_Buero_Deckenfluter.sendCommand(OFF)
else Licht_Buero_Deckenfluter.sendCommand(newDim)
end
But IMHO it’s much easier to use items and you’re less likely to have syntax issues.
I changed the alarm:smoke to alarm_smoke at the end of the channel name as that what is showing under its channel name as per screenshot I sent?
ive updated the rules to:
rule "Fire in Office"
when
Item Alarm changed to ON
then
logInfo("notifications", "Smoke Detected in Office")
sendNotification("xxxxxxxx@gmail.com", "Smoke Detected in Office")
end
Yes if that is what’s in PaperUI then it’s correct and you can copy and paste that if you like. I had a hard time viewing the screen shot but you get the idea. Also go to PaperUI and look for the Alarm item and make sure the channel is linked e.g. click the blue button.
I changed the rule so you only get notified if the smoke alarm changed to ON.
Have you tested the new item/rule and watched the logs for errors?
yes all changes made and double checked everything both items and rules file. logs aren’t showing up anything when I press the test button on the smoke detector for a few seconds. The smoke detector is sounding and flashing. I checked the PaperUI and it is already checked. I did try disabling it and then enabling it again but that came back with an error not found message. Hadn’t seen that before. The other channels - binary sensor and battery did seem to enable/disable ok.
I have tested the smoke alarm when I was messing around with Home Assistant and pressing the test button did simulate the same outcome if smoke was detected. I did get notified using HA so assumed it must act in the same way with OpenHab? Or is my assumption the mother of all frack ups?
OK tried that and I noticed in the logs this is shown when you disable and enable it via PaperUI
2020-02-21 18:47:59.311 [.ItemChannelLinkAddedEvent] - Link 'zwave_device_7763853a_node6_alarm_smoke-zwave:device:7763853a:node6:alarm_smoke' has been added.
Ive also tried this thinking that the channel name should have actually been this all along but still no joy. In the items file I pasted this directly as above.
So my rules file looks like this now:
rule "Send Mobile Push Notification"
when
Item Send_via_App_Switch changed
then
if(Send_via_App_Switch.state == ON)
{
logInfo("notifications", "Sending notification via app.")
sendNotification("xxxx@gmail.com", "Notification sent via app.")
Send_via_App_Switch.postUpdate(OFF)
}
end
rule "Send Notification via Mail"
when
Item Send_via_Mail_Switch changed
then
if(Send_via_Mail_Switch.state == ON)
{
logInfo("notifications", "Sending notification via mail")
sendMail("xxxxx@gmail.com", "Mail Notification", "Notification sent from OpenHab")
Send_via_Mail_Switch.postUpdate(OFF)
}
end
rule "Fire in Office"
when
Item Alarm changed to ON
then
logInfo("notifications", "Rule for Fire in Office triggered")
sendNotification("xxxxx@gmail.com", "Smoke Detected in Office")
end
my items file is:
Switch Send_via_App_Switch "Send via App" <switch>
Switch Send_via_Mail_Switch "Send via Mail" <switch>
Switch Send_via_Telegram_Switch "Send via Telgram" <switch>
Switch Alarm "Office Smoke" <switch> {channel="zwave_device_7763853a_node6_alarm_smoke-zwave:device:7763853a:node6:alarm_smoke"}
I also tried toggling the channel link off and on via PaperUI.
Via Paper UI and the logs its stating it as ’zwave_device_7763853a_node6_alarm_smoke-zwave:device:7763853a:node6:alarm_smoke'
Why does it repeat itself but one uses underscores and the other using colons?
OK I stopped OH, cleaned the cache and rebooted. Its running on a Raspberry Pi Model 4 and it was installed as instructions per OpenHab’s website.
I also have a toggle switch I setup previously and I just checked that again and it works fine so I definitely 100% know that notifications are working and I can also see the notification within myOpenHab.
Something very odd is going on because I have two of those smoke sensors and they both are showing as the same device code except for the node of which they are attached. so the office one didn’t work. I just tried the other one from the lounge and pressing the button notifications worked!!!
I removed the Office smoke detector from OpenHab and reset it to factory settings then re-added it as new to OpenHab. Made sure the rules and items files were updated to reflect any changes. Oddly this still won’t work. If I unpair the Office one from OpenHab again I can see it going Offline and the Lounge smoke sensor 007 is still there and it works o.k. even sending notifications.
Is the problem because of the device id is the same? shouldn’t these Z-Wave devices be showing unique device id’s?