the first switch controls the relay
the contact is connected to the push button wired from GND to GPIO13 (in my case) input of my ESP
so…
i can see in openhab the changes of state of my pushbutton… this means that the signal enter correctly in OH. and also i can set the light ON and OFF by my switch…
i am in trouble with a rule that when the pushbutton change the state from on to off …
if the light is ON then switch it OFF and change state.
if the light is OFF then switch it ON and change state…
Create a rule that triggers when the hardwareswitch changes and send a command to toggle the state on the switch. NOTE: “switch” is a terrible name for an Item. It is too close to a reserved word. I recommend using a more descriptive name.
switch.sendCommand(if(switch.state == ON) OFF else ON)
Thank you seems to work but now i noticed 2 Things
Every time i change a the state in the log windows appears
016-11-02 01:38:45.645 [INFO ] [runtime.busevents ] - Luce_Studio state updated to OFF
2016-11-02 01:38:46.080 [WARN ] [t.i.s.MapTransformationService] - Could not find a mapping for ‘-’ in the file ‘en.map’.
also i noticed (ask to you how to initialize all lights on startup)
all my lights can receive the state via mqtt. but i am confused to use the postupdate command
something similar to this
rule "Initialize light states"
when
System started
then
Lights?.members.forEach(lights|
postUpdate(light,??????????????????)
)
end
Your Item is not initialized. I’m not sure what the mapping error is referring to though. I don’t see any map. Do you have any other uninitialized Items that have a Map? The timing might be a coincidence.
And this is where the choice of “switch” for an Item name is causing problems. “switch” is a reserved word. Rename your Item to something else, something more descriptive and not a reserved word and, assuming that whatever you rename “switch” to is not undefined the above should work.
However, a more “correct” approach might be to use persistence and restoreOnStartup.
Actually yes you can if you use the MQTT Action you can publish messages to the topics which could cause the devices to publish their states. But you can’t get the last state the devices published because once read the message goes away.
Hi… i changed names before posting my preview message.
I wrote switch because i was trying update the switch state. Now the item has another name.
For the mqtt i prefeer the items publish their state at startup because i can usa the switches also by phisical button. So when oh coming up the state can be different.
It depends on your remote devices. I have my system set up with a System started rule that publishes a message to a topic all my remote devices subscribe to. When the devices see a message posted to that topic they publish their current state to their respective topics.
However, this requires both OH (the System started rule) and the devices to support this. There is nothing built into the MQTT binding or anything else that does this for you.
i can send an MQTT message to all my esp with openhab (setting a rule) but how can set ESPeasy to receive this and reply with the status of the device? a dummy device?
CIao Damiano,
se puoi aiutarmi il mio progetto consiste nel far arrivare i contatti puliti di ogni pulsante fisico in casa alle gpio di raspberry,
Alla raspberry collegare poi una o due schede a 8ch a relè tipo quelle della Sainsmart, dove poi verranno collegati i carichi (luci).
Per cui si avrebbe la possibilità di controllare quale carico o carichi azionare alla pressione di quel pulsante fisico o pulsante web.
Piuttosto che attivare degli scenari alla pressione prolungata ecc ecc.
E’ una cosa fattibile da fare con openhab2?, se si quale protocollo devo utilizzare?,