Switch item with Transform map for MQTT item

Hi All

I feel utterly retarded but I can’t work out what im doing wrong with my transform. Item showing OFF, when the transform map has

OFF=CLOSED
Switch Garage "Garage Roller Door" [ "Switchable" ] { mqtt=">[broker:cmnd/gate/POWER3:command:*:default], <[broker:stat/gate/POWER3:state:MAP(door.map)]", autoupdate="false" }

Can someone please enlighten me sigh

Thankyou

Is that the full map file?

What is the message actually being received. Not what you think it should be, but actually received?

hi Rich

door map:

ON=OPEN
OFF=CLOSED
NULL=NULL

items file:


/*Group Definitions for Door Sensors*/
Group:Contact:OR(OPEN, CLOSED) gDoorSensors "The doors are [%s]"
Group:DateTime:MAX gDoorsLast "The last door event was [%1$tm/%1$td %1$tH:%1$tM]"
Group:Switch:OR(ON, OFF) gDoorsTimers

/* Gates & Garage*/
Switch Gate_full      "Fully"                         [ "Lighting" ]   { mqtt=">[broker:cmnd/gate/POWER1:command:*:default], <[broker:stat/gate/POWER1:state:default]", autoupdate="false" }
Switch Gate_partial   "Partial"                       [ "Lighting" ]   { mqtt=">[broker:cmnd/gate/POWER2:command:*:default], <[broker:stat/gate/POWER2:state:default]", autoupdate="false" }
Contact Gate_status   "Gate Status"    (gDoorSensors) [ "Switchable" ] { mqtt="<[broker:cmnd/SENSOR/POWER8:state:MAP(door.map)]" }
Contact Garage_status "Garage status"  (gDoorSensors) [ "Switchable" ] { mqtt="<[broker:cmnd/2_garagedoor/POWER2:state:MAP(door.map)]" }
Switch Garage         "Garage Roller Door"            [ "Switchable" ] { mqtt=">[broker:cmnd/gate/POWER3:command:*:default], <[broker:stat/gate/POWER3:state:MAP(door.map)]", autoupdate="false" }

DateTime Gate_status_LastUpdate   "Sliding Gate Opener [%1$tm/%1$td %1$tH:%1$tM]" (gDoorsLast)
DateTime Garage_status_LastUpdate "Garage Door Opener  [%1$tm/%1$td %1$tH:%1$tM]" (gDoorsLast)

Switch Gate_status_Timer                                                          (gDoorsTimers)  { expire="1m,command=OFF" }
Switch Garage_status_Timer                                                        (gDoorsTimers)  { expire="1h,command=OFF" }


10:58:03.155 [DEBUG] [binding.mqtt.internal.MqttItemBinding] - Publishing command ON to cmnd/gate/POWER3
10:58:03.306 [WARN ] [ab.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'Garage'
10:58:04.259 [WARN ] [ab.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'Garage'
10:58:08.191 [INFO ] [smarthome.event.ItemStateChangedEvent] - UPS_Input_Voltage changed from 239.0 to 237.0
10:58:08.193 [INFO ] [smarthome.event.ItemStateChangedEvent] - UPS_Current_Load changed from 33 to 34

Convert the Item to a String Item and take the transform off of the incoming to see what is actually being sent to your Item. Compare that to what you have in your MAP. Watch for leading or trailing spaces.

Thanks Rich, like so?

String Garage         "Garage Roller Door"            [ "Switchable" ] { mqtt=">[broker:cmnd/gate/POWER3:command:*:default], <[broker:stat/gate/POWER3:state:default]", autoupdate="false }

Doesnt work im afraid


11:38:23.624 [ERROR] [ipse.smarthome.core.items.GenericItem] - Tried to set invalid state OFF (OnOffType) on item Garage of type StringItem, ignoring it

Are you sure this error is coming from this Item? You can set any MQTT message to a String Item.

Absolutely it is. The error says ‘on item Garage’

Can we go back a step? If the Item is a Switch type, you can’t update it to CLOSED. Switches take ON-OFF-NULL-UNDEF states.

If you want to transform a switch Item ON/OFF state to something else for display, that’s fine, but you put the transform in the label’s [ ] format part.

rossko, this is only about formatting the state. Nothing more… I want the ON/OFF commands to remain as is, there’s no issue but my rules for alerts work on things being OPEN or CLOSED.

This is why I put the transform in the state section, is that not correct?

Switch Garage         "Garage Roller Door"            [ "Switchable" ] { mqtt=">[broker:cmnd/gate/POWER3:command:*:default], <[broker:stat/gate/POWER3:state:MAP(door.map)]", autoupdate="false" }

As rossko says, a Switch can only be ON or OFF. You can’t transform the state to OPEN CLOSED and still use it with a Switch. If you’re Role need it to be OPEN CLOSED, you need to use a Contact item.

OK, so a contact will report status but it would be a different sensor given I cannot send an ON/OFF to a contact. So im stuffed basically!

Try that. As far I understand you want the switch keeping on/off internally and just open/closed for display purposes.

Switch Garage "Garage Roller Door [MAP(door.map):%s]" [ "Switchable" ] { mqtt=">[broker:cmnd/gate/POWER3:command:*:default], <[broker:stat/gate/POWER3:state:default]", autoupdate="false" }

No, not stuffed. You need to adapt your rules. Let’s say you have a rule triggered from a change of a group of contacts to OPEN. You add a trigger for a similar group of switches changing to ON or whatever. And obviously change the rule code to handle either case.

Another approach would be to make a virtual Contact Item mirroring your switch. Traditionally you’d use a little rule; these days you can use a follow profile I think.

2 Likes

thanks rossko57, given neither will actually tell me correctly if the door is open I think a contact sensor is the best idea with a proper reed function.

Never heard of the follow profile, will look into that though! neat