Hi
I am beginner in Openhab.
I want to create scene with mqtt nodemcu as switch ,whenever we push the manual button scene activate or deactivate.
I have two more mqtt nodemcu device which is connected with led.
I want to those device activate or deactivate by pressing a switch but i dont have idea how to create scene,item,sitemap,rules etc.
please
help
Thanx
My item file:
Switch lamp1 “Office Lamp1” (all){mqtt=">[mosquitto:/home/1/esp01/p1/com:command:on:ON],>[mosquitto:/home/1/esp01/p1/com:command:off:OFF],<[mosquitto:/home/1/esp01/p1/state:state:default]"}
First, please change all smart quotes to normal quotes as openHAB does not accept smart quotes at all (but this error may have been caused by copy and paste to the forum)
In question of scenes: an easy way would be a rule, triggered by the scene switch:
rule "my scenes"
when
Item button received command
then
if (receivedCommand==ON) {
lamp1.sendCommand(ON)
lamp2.sendCommand(ON)
}
else if (receivedCommand==OFF) {
lamp1.sendCommand(OFF)
lamp2.sendCommand(OFF)
}
end
If the button does only send ON commands, you could use another rule:
var int counter = 0
rule "my scenes"
when
Item button received command
then
if (receivedCommand==ON) {
counter = counter + 1
if (counter > 3)
counter = 0
}
switch counter {
case 0: {
lamp1.sendCommand(OFF)
lamp2.sendCommand(OFF)
}
case 1: {
lamp1.sendCommand(ON)
lamp2.sendCommand(OFF)
}
case 2: {
lamp1.sendCommand(ON)
lamp2.sendCommand(ON)
}
case 3: {
lamp1.sendCommand(OFF)
lamp2.sendCommand(ON)
}
}
end
This would result in a scene button which would switch through 4 different scenes. In fact, this would be more like a serial switch (don’t know if this is the correct english expression, for details see https://de.wikipedia.org/wiki/Serienschaltung, no english wiki page, but good schematics - “Seriendrehschalter”). When using more lights, one would not increase steps but define only a few scenes with the preffered lighting.
Thanks it’s working but still i have problem.
Openhab item button working well and switch on off another two devices as i want in my scene but manual mqtt push buttons which is connected with nodemcu not working. Whenever we pushed the button scene not activated.may be mistakes in my item or rule
please help
there is scene “Bedroom Light” is a manual button or push button which is connected with mqtt nodemcu
and i want to operate "Room Light and “kitchen Light” by this scene button ON-OFF manually buttton and by openhab GUI.
rule "my scenes"
when
Item scene received command
then
if (receivedCommand==ON) {
home1.sendCommand(ON)
home2.sendCommand(ON)
}
else if (receivedCommand==OFF) {
home1.sendCommand(OFF)
home2.sendCommand(OFF)
}
end
OK, from looking at your rule and looking at your question I’m not sure you understand how this is working.
The scene will only change if you send a command to the scene Item. Pressing a physical button on one of the lights does not send a command to the scene Item.
If you want to have the scene change when you toggle a light from the physical switch, you will need to write rules that trigger when the light changes and send a command to the scene as appropriate.
I don’t want to come across as not helpful, but I’ve been down this path before and it ends up being nothing but a time sync. You won’t get what you want and I will have wasted time that I could have spent helping many other users.
We have provided everything in this thread that you should need in terms of examples to implement this yourself. If you cannot then you need to study the Rules and Items you have already working and understand how they work. Once you do it will be trivial to implement this yourself.
I will be happy to answer any specific questions about the examples you may have, but I will not write this for you.
the first “state” in “state:state:default” is the last part of the topic your device is publishing to.
The second “state” means that the messages you read on the topic “/home/2/esp02/p1/state” will cause an update to the Item, not a command.
The “default” means you do not want the MQTT binding to make any changes to the incoming message before attempting to assign it to the Item.
So, if the device publishes “ON” to “/home/2/esp02/p1/state”, the binding will do a postUpdate(ON) to the state. So you will want to trigger an Item using received update or changed for any Rule that you want to execute when the Item is toggled from the device.
Whenever power goes of my raspberry pi and mqtt devices,openhab restart and change its state as default all light OFF but i want that whenever power goes OFF and again ON that the device state remain same as previous. Please help!!! How can i solve it?