Switch with a sensor attached

hi,

I have a switch set up to my garage door. The open/close MQTT commands are

garage/door/1/action
OPEN/CLOSE

I also have a sensor set up which tells me if the door is open or closed

garage/door/1/status
open/close

How can I show the status of the garage door on the switch, or is it better to use a contact? I have the switch working but not the contact. I was also wondering how to get the contact working

Switch:
Switch GarageDoor “Open/Close Garage Door” { mqtt=">[broker:garage/door/1/action:command:ON:OPEN],>[broker:garage/door/1/action:command:OFF:CLOSE]"}

Contact
Contact GarageDoorSensor “Garage Door [%s]” { mqtt="<[broker:garage/door/1/status:state:default]" }

Contacts are basically read-only.

On which UI?

Thanks!!!

I am using basic ui. I understand that the contact is basically a text field. I think I am having an issue translating the mqtt message to a switch

The mqtt messages above have the correct case. Could I need a mapping file?

I m not that familiar with the basic UI but if u want to try HABPanel I can def assist u w that

Show us your item definition please.

For debugging - I sometimes define items as Text - then I can know for sure what message is OH understanding.

Nadir,

I got it working, I think it was a mapping between open and OPEN

Contact GarageDoorSensor “Garage Door [%s]” { mqtt="<[broker:garage/door/1/status:state:CLOSED:closed],<[broker:garage/door/1/status:state:OPEN:open]" }

Can I take the same state and apply it to the switch as well?

No, Switches can only accept ON or OFF. You would have to map the OPEN/CLOSED to ON/OFF to set it to a Switch.

The question is why would you want to? The sensor that indicates whether the door is open is separate from the Switch that triggers the garage door opener. What are you hoping to achieve?

hi Rich,

First thanks for all the examples!!!

I am using an esp8266 to control the garage. I mixed up the cases on the commands so I had to translate some of the items. I wanted the switch UI component to indicate if the garage was open or closed. The garage door might be activated by another transmitter. So I thought to send a state command to the switch when the reed switch was activated. The following is working but ugly

Switch GarageDoor “Garage Door” Switch GarageDoor “Open/Close Garage Door” { mqtt=">[broker:garage/door/1/action:command:ON:OPEN],>[broker:garage/door/1/action:command:OFF:CLOSE],<[broker:garage/door/1/status:state:CLOSED:closed],<[broker:garage/door/1/status:state:OPEN:open]"}

How I do it might be informative:

Items:

Switch aGarageOpener1 "Garage Door Opener 1"

Contact vGarageOpener1 "Garage Door Opener 1 is [MAP(en.map):%s]"
  <garagedoor> (gDoorSensors,gDoorCounts)
  { mqtt="<[mosquitto:entry_sensors/main/garage/door1:state:default]" }

String GarageOpener1_Cmd
  { mqtt=">[mosquitto:entry_sensors/main/garage/door1/cmd:state:*:default]" }

I coded this way back when there wasn’t an MQTT Action so I use a proxy Item for the actuator and the Item that sends the command to the opener (RPi wired to a relay wired to the button). That is why there is the aGarageOpener1 and GarageOpener1_Cmd. I also have two separate Items because I want to intercept the command to open the garage and do some stuff before acutally opening the garage you will see in my rule below. The vGarageOpener1 is the open/closed sensor.

Rules:

rule "A Garage Opener was triggered"
when
  Item aGarageOpener1 received command or
  Item aGarageOpener2 received command
then
  // forward the command to the opener
  var topic = triggeringItem.name.substring(1) + "_Cmd"
  sendCommand(topic, "ON")

  // log and generate an alert if the controller is offline
  logInfo(logName, "Garage opener " + triggeringItem.name.substring(triggeringItem.name.length-1) + " was triggered.")
  if(vNetwork_Cerberos.state == OFF) {
    aAlert.sendCommand("Attempting to trigger a garage opener but the controller is offline!")
  }
end

Sitemap:

                Switch item=aGarageOpener1 icon="garagedoorclosed" mappings=[ON=Open]  visibility=[vGarageOpener1 == CLOSED]
                Switch item=aGarageOpener1 icon="garagedooropen"   mappings=[ON=Close] visibility=[vGarageOpener1 == OPEN]
                Switch item=aGarageOpener2 icon="garagedoorclosed" mappings=[ON=Open]  visibility=[vGarageOpener2 == CLOSED]
                Switch item=aGarageOpener2 icon="garagedooropen"   mappings=[ON=Close] visibility=[vGarageOpener2 == OPEN]

On the sitemap I put the actuator proxy Item with a custom icon to show the door open or closed and use a mapping to get a button labeled Open or Close. I have an Open and Close version for each door and use the visibility element to only show one of them at a time based on the state of the door sensor.