Mqtt topic reading a switch as a contact

I have a tasmota with a pin configured as a switch, and I am trying to read it as a contact
I tried every ting I could think of

thing:
Type switch : heatingstatus-man6 "monitorizare releu incalzire mansarda" [ stateTopic="tele/nodemcu-v3-mansarda/SENSOR", transformationPattern="JSONPATH:$.Switch3" ]

item:
Contact heatingstatus_man7 “Status incalzire mansarda” (E2_Hol) { channel=“mqtt:topic:nodemcu-v3-mansarda:heatingstatus-man6”[profile=“transform:MAP”, function=“tasmotacontact.map”], expire=“15m”}
String heatingstatus_mans “Status incalzire mansarda string” (E2_Hol) { channel=“mqtt:topic:nodemcu-v3-mansarda:heatingstatus-man6”[profile=“transform:MAP”, function=“tasmotacontact.map”], expire=“15m”}

tasmotacontact.map:
ON=OPEN
OFF=CLOSED

I can read it as a string (heatingstatus_mans) but not as a contact
any ideea why? or another way to transform it?

Hi,

What value does JSONPATH:$.Switch3 return? Assuming it returns ON or OFF.

based on https://www.openhab.org/v2.4/addons/bindings/mqtt.generic/#channel-type-contact-switch and https://www.openhab.org/v2.4/addons/bindings/mqtt.generic/#full-example :

Type contact : heatingstatus-man6 "monitorizare releu incalzire mansarda" [ stateTopic="tele/nodemcu-v3-mansarda/SENSOR", transformationPattern="JSONPATH:$.Switch3" ]

Contact heatingstatus_man7 “Status incalzire mansarda” (E2_Hol) { channel=“mqtt:topic:nodemcu-v3-mansarda:heatingstatus-man6”, expire=“15m”}

Should work?

If JSONPATH:$.Switch3 returns something else, you could add
, on="whateverthevalueONis", off="whateverthevalueOFFis"
to your channel configuration.

1 Like

The difficulty there in your original scheme is that the transform profile only currently works works with String type. The string “CLOSED” that your MAP returns is not the CLOSED type that a Contact Item needs.

Note - When you use a MAP in the binding config, the channel takes care of String to Item type conversions. It’s only transform profile that is limited.

Ah, yeah that’s what I thought also but I wasn’t a 100% sure…

switch3 returns “ON” or “OFF”
I tried before specifying in the channel open=“on”, close='off" but it did not work, if I remember it complained that it’s a string

so what other solutions do you propose, except of using it just a switch (I dont like it because you can change it in the UI)

no not really

Switch      SwitchWhitchIsNotSwitch "surprise [MAP(magic.map):%s]"

map file:
ON=whatever
OFF=something

on sitemap you’ll be left just with text not switch


underline.
From posts like this I feel like majority of people trying to reinvent wheel and overcomplicating things. Simpliest solution is always the best.

sounds good enough, thanks

I tried:
Switch heatingstatus_mant1 "status test [MAP(tasmotacontact.map):%s]" <radiator> (E2_Hol) { channel="mqtt:topic:nodemcu-v3-mansarda:heatingstatus-man8", expire="15m"}

image

I can autoupdate=“false”, this makes it only change in UI, but I would like it not to do even that :slight_smile:

I can show it as text item in sitemap, this way it can’t be clicked

see the difference …

item:

Switch SwitchTest   "test [MAP(test.map):%s]" <switch>

map file

ON=it's on
OFF=it's off

sitemap:

	Frame label="Test" {
		Text item=SwitchTest
		Switch item=SwitchTest
	}

output
test

1 Like