I’m trying to connect my tasmota (sonof) device with my openhab server. Somehow, it doesn’t work. Since I like coding I’m trying with the config files. But it get’s messed up.
What does work:
Embedded broker is online and working.
If i use my pc as a client, I can command the tasmota
So I assume that the fault is in my code. So I post it here. Maybe you see some error?
rule "Tasmota_ON"
when
Item Bathroom_Tasmota_Switch changed from OFF to ON
then
Bathroom_Tasmota_Relay.sendCommand(ON)
end
rule "Tasmota_OFF"
when
Item Bathroom_Tasmota_Switch changed from ON to OFF
then
Bathroom_Tasmota_Relay.sendCommand(OFF)
end
I guess my sitemap is not really needed sinde I dond’t get error’s here.
My problem is or in my things file, or in my items file. One of the 2
Can you post the logs you get from fronttail when trying to use the rule above.
Sitemap has nothing to do with your rules. Can you turn on/off the switch using BasicUI?
Maybe try the rule this way and see what happens.
rule "Tasmota_ON"
when
Item Bathroom_Tasmota_Switch changed
then
if (Bathroom_Tasmota_Switch.state == OFF)
Bathroom_Tasmota_Relay.sendCommand(ON)
end
rule "Tasmota_OFF"
when
Item Bathroom_Tasmota_Switch changed
then
if (Bathroom_Tasmota_Switch.state == ON)
Bathroom_Tasmota_Relay.sendCommand(OFF)
end
Also note if you are using OH version 2.4 you will need to restart OH each time you make a change to your MQTT item file. This has been fixed in OH 2.5 milestone versions.
==> /var/log/openhab2/events.log <==
2019-11-17 16:22:07.696 [hingStatusInfoChangedEvent] - 'mqtt:broker:mosquitto' changed from OFFLINE to ONLINE
2019-11-17 16:22:07.702 [me.event.ThingUpdatedEvent] - Thing 'mqtt:broker:mosquitto' has been updated.
2019-11-17 16:23:33.450 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Switch' received command ON
2019-11-17 16:23:33.473 [vent.ItemStateChangedEvent] - Bathroom_Tasmota_Switch changed from OFF to ON
2019-11-17 16:23:33.504 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Relay' received command ON
2019-11-17 16:23:33.512 [nt.ItemStatePredictedEvent] - Bathroom_Tasmota_Relay predicted to become UNDEF
2019-11-17 16:23:37.193 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Switch' received command OFF
2019-11-17 16:23:37.206 [vent.ItemStateChangedEvent] - Bathroom_Tasmota_Switch changed from ON to OFF
2019-11-17 16:23:37.226 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Relay' received command OFF
2019-11-17 16:23:37.234 [nt.ItemStatePredictedEvent] - Bathroom_Tasmota_Relay predicted to become UNDEF
2019-11-17 16:29:25.459 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Switch' received command ON
2019-11-17 16:29:25.474 [vent.ItemStateChangedEvent] - Bathroom_Tasmota_Switch changed from OFF to ON
2019-11-17 16:29:25.499 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Relay' received command ON
2019-11-17 16:29:25.510 [nt.ItemStatePredictedEvent] - Bathroom_Tasmota_Relay predicted to become UNDEF
2019-11-17 16:29:27.776 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Switch' received command OFF
2019-11-17 16:29:27.801 [vent.ItemStateChangedEvent] - Bathroom_Tasmota_Switch changed from ON to OFF
2019-11-17 16:29:27.817 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Relay' received command OFF
2019-11-17 16:29:27.825 [nt.ItemStatePredictedEvent] - Bathroom_Tasmota_Relay predicted to become UNDEF
So There’s some action when I use the switch. But the mqtt code never gets to the tasmota.
Simple rule, using cron to turn on/off the couch light at a certian time.
rule "Turn Couch Light On"
when
Time cron "0 30 18 ? * *"
then
CouchLight.sendCommand(ON)
end
rule "Turn Couch Light Off"
when
Time cron "0 30 23 ? * *"
then
CouchLight.sendCommand(OFF)
end
Yes, I’m on OH2.4 and never did a reboot. I also never made a generic thing in the paper UI. I assumed that the code would do the trick. Since my brooker came in the UI that way. But I can be mistaken!
It’s a sonoff basic indeed. I use 2 Item’s as well. One for the switch defined in my basic UI and then one for the handling to MQTT. Some reasoning mistake as well?
Name it what you like but that’s where the channel is linked to the item. Some recommend that you create the Thing using PaperUI only and then files for items. I’ve never tried it that way, as you see above, but toy with it and see what happens.
As for the rule I would start with being able to turn on/off the switch using BasicUI first. Then move to rules.
Make sure you do not have simple mode turned on in PaperUI, else you may end up with duplicate items.
You only need to restart if changing/editing the actual file in /etc/openhab2/items. Are you using VSCode or other for editing files?
From command line you do not have to reboot just use sudo systemctl stop openhab2 then sudo systemctl start openhab2. It is also a good idea to stop OH before rebooting as well.
Wow you really know how to debug. Simple mode is indeed on! Because I followed that instruction.
So after reboot:
2019-11-17 17:04:42.776 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Switch' received command ON
2019-11-17 17:04:42.795 [vent.ItemStateChangedEvent] - Bathroom_Tasmota_Switch changed from NULL to ON
2019-11-17 17:04:44.008 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Relay' received command OFF
2019-11-17 17:04:44.016 [nt.ItemStatePredictedEvent] - Bathroom_Tasmota_Relay predicted to become NULL
2019-11-17 17:04:47.989 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Switch' received command OFF
2019-11-17 17:04:48.004 [vent.ItemStateChangedEvent] - Bathroom_Tasmota_Switch changed from ON to OFF
2019-11-17 17:04:48.031 [ome.event.ItemCommandEvent] - Item 'Bathroom_Tasmota_Relay' received command ON
2019-11-17 17:04:48.043 [nt.ItemStatePredictedEvent] - Bathroom_Tasmota_Relay predicted to become NULL
FYI, NULL - indicates an Item is not yet initialized. You only need a switch item, not sure why you have both relay and switch unless your using it as some type of proxy item.
Now I’m afraid I’ve to many items. (ignore the online thing, that’s just to see if my phone is in the wifi or not)
To answer your question:
I thought: 1 device to define the switch on my basic UI and 1 devide to define the relay I want to control. But I may be wrong
rule "Tasmota"
when
Item Bathroom_Tasmota_Switch changed
then
if (Bathroom_Tasmota_Switch.state == ON) {
Bathroom_Tasmota_Switch.sendCommand(OFF)
}
else if (Bathroom_Tasmota_Switch.state == OFF){
Bathroom_Tasmota_Switch.sendCommand(ON)
}
end