Hello all,
Firstly, I am new to openhab but what a fantastic bit of software! I am familiar with programming but mainly on cpp.
My first challenge is setting up all the sonoff switches in my house on openhab. All are flashed with tasmota.
Plenty of tutorials on how to do this and I have got it working fine for an individual module.
It seems odd to me that I have to copy and paste this code for each sonoff device and change the unique ID. Copy and pasting code is bad!
Is there a way of creating a dynamic rule?
My though process is:
- A rule that is a single line for each of; on, off, status etc etc etc. e.g. in “sonoff.items”:
Switch sonoff_reachable "Sonoff Alive" { mqtt="<[mqtt:tele/sonoff_dynamic_UID_goes_here/tele/LWT:state:MAP(unreach.map)]" } Switch sonoff_switch "Sonoff Switch" <bedroom> (bedroom) { mqtt=">[mqtt:cmnd/sonoff_dynamic_UID_goes_here/power:command:*:default], <[mqtt:stat/sonoff-0002bedroom/POWER:state:default]" } Number sonoff_rssi "Sonoff RSSI [%d %%]" { mqtt="<[mqtt:tele/sonoff_dynamic_UID_goes_here/STATE:state:JSONPATH($.Wifi.RSSI)]" }
- In the sitemap or elsewhere I then define “Bedside_lamp” as “sonoff-ABCD” so that I can do Bedside_lamp.on or Bedside_lamp.status or whatever and it puts the UID into the rule and does the job. e.g. “myhome.sitemap”:
sitemap home label="My Home" { Frame label="Bedroom" icon="bedroom"{ Switch item=sonoff_switch("sonoff-ABCD") label="Lamp" Text item=sonoff_rssi("sonoff-ABCD") Switch item=sonoff_switch("sonoff-1234") label="Fan" Text item=sonoff_rssi("sonoff-1234") } }
Here’s hoping I’ve explained that well. I think it is something that may may many lives easier!
Cheers