Can same switch item publish ON:OFF and ON1:OFF1?

Hi
so as topic says i want to publish two different commands to arduino but on the same channel.
Let say i want one off my relays to send pulse (ON pause OFF) signal and i want to have another on1 off1 buttons to send another (ON pause OFF pause ON pause OFF) on the same relay.

So far i made another command listener on arduino and awaits ON1 and OFF1 commands, but i cant send them from Openhab, If its possible to make this pulses through Openhab only, some examples are welcomed :slight_smile:.

Here is what i tried so far

items

Switch Relay1 "AC Restart relay"           <garagedoor>    (All) {mqtt=">[mymosquitto:openhab/floor1/relay1:command:ON:ON],>[mymosquitto:openhab/floor1/relay1:command:OFF:OFF]"}
Switch Relay11 "AC Once relay"           <garagedoor>    (All) {mqtt=">[mymosquitto:openhab/floor1/relay1:command:ON1:ON1],>[mymosquitto:openhab/floor1/relay1:command:OFF1:OFF1]"}

sitemap

Switch item=Relay1 mappings=[OFF="OFF", ON="ON"] 
Switch item=Relay11 mappings=[OFF1="OFF", ON1="ON"]

Thanks

You can combine the bindings configs onto one Switch which will cause it to send “ON” and “ON1” whenever you press the switch it will send both ON and ON1 at the same time.

But if you are looking to have one Switch send an ON sometimes and an ON1 other times, how is it supposed to know which one you want? A Switch is just a toggle, a boolean, it can only be ON or OFF. You would need something else (a second switch perhaps) to tell it which one you want.

However, if you make it a Number Item you can put it on your sitemap as a Switch with a Mappings which will put four buttons on the sitemap. Then your binding would be something like

mqtt=">[mymosquitto:openhab/floor1/relay1:command:0:ON],>[mymosquitto:openhab/floor1/relay1:command:1:OFF],>[mymosquitto:openhab/floor1/relay1:command2:ON1],>[mymosquitto:openhab/floor1/relay1:command:3:OFF1]"

And the sitemap would be something like

Switch item=Relay1 mappings=[0="ON", 1="OFF", 2="ON1", 3="OFF1"]

However, not knowing what exactly it is you are doing, I would have thought it would make the most sense to have two separate Switches to control each behavior separately.

Thanks for the answer,
the point is that i control my AC through remote and on that remote i installed relay on the ON button, so when i press ON in openHAB it sends (ON pause 1sec than OFF) and it acts like i pressed the button on that remote.
But when the power outage happens, my AC unit is off and the remote for the AC is still on, so to send another ON command to the AC unit, first i need to turn off that remote with (ON pause 1sec OFF) and than turn back on with (ON pause 1sec OFF). With little modifications and with your help now its working :slight_smile: .

Can you please help me with one more thing :blush:,
i also installed AC status relay to tell me if its on or off, and i made rules for the same switch again with your help in another topic :slight_smile: , here is the code for the rules



rule "Reset AC on startup"
when
    System started
then
    if (Relay11.state == ON && Switch5.state == OFF ) { 
    Relay1.sendCommand(ON)    
    Relay1.sendCommand(OFF)
		// send email notification 
    }
end

and items

Switch Relay1 "AC Restart relay"           <garagedoor>    (All) {mqtt=">[mymosquitto:openhab/floor1/relay1:command:ON:ON],>[mymosquitto:openhab/floor1/relay1:command:OFF:OFF]"}
Switch Relay11 "AC Once relay"           <garagedoor>    (All) {mqtt=">[mymosquitto:openhab/floor1/relay1:command:ON:ON1],>[mymosquitto:openhab/floor1/relay1:command:OFF:OFF1]"}
Contact Switch5 "AC Status [MAP(en.map):%s]"  <garagedoor> (Sensors) {mqtt="<[mymosquitto:openhab/floor1/switch5:state:default]"}

but when i tested and when the openHAB reboots in the middle of that process i turned on the AC, but the openHAB thought that is OFF because off RRD4J persistence and tried to turn ON again but actually it turned OFF.
So the question is…
Is it possible to initialize the current state of my switch, or to call for that state before the rules apply?

It depend on whether your device support it. Personally I solve this problem by having OH publish a “send update” message to my devices which causes the devices to publish their current state. This update request message is sent in the System started rule.

Then you can sleep for a bit to give the devices a chance to report their current status and then do the rest of your logic.

Without some way for OH to request the current state, there is no way for OH to know what state the device may be in when it comes up. All if has to go on is the value in rrd4j.

Yep, you are the man my friend :slight_smile:
I was struggling to make it work, i knew that is possible because with arduino and openHAB everything is possible :smiley:

So here is what ive done
in items i put another line

Switch Status5 "Check AC Status on startup"           <garagedoor>    (All) {mqtt=">[mymosquitto:openhab/floor1/chkstatus:command:ON:CHKSTATUS]"}

than in rules on the top of the code i added

Status5.sendCommand(ON)

and that triggered event in arduino that brought back in openHAB the current status.
arduino code

  if (msgString.equals("CHKSTATUS")) {
  if (digitalRead(switch5)==HIGH){
  client.publish("openhab/floor1/switch5","OPEN");  
      }
  else {
  client.publish("openhab/floor1/switch5","CLOSE");
    
}
}

Thanks AGAIN!!!