4est
(Dan Padure)
March 5, 2020, 8:03pm
1
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?
tsmit
(Tom Smit)
March 5, 2020, 9:43pm
2
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
rossko57
(Rossko57)
March 5, 2020, 10:23pm
3
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.
opened 10:41PM - 19 Jun 19 UTC
closed 11:12AM - 04 Aug 20 UTC
Profiles allow for manipulation of values in between Items and binding channels.…
Transform profiles allow user-defined manipulations e.g. numeric SCALE or arbitrary javascript JS.
Unfortunately, transform "output" is in string form.
Those bindings that support "upstream" transforms (i.e between binding and channel) allow the user to output from a JS transform into a number channel, presumably carrying out some parsing somewhere.
But when used as a profile, attempts to route transform (string) output to a Number type Item are silently rejected.
This really a restatement of [#4995](https://github.com/openhab/openhab2-addons/issues/4995) which was closed "won't fix", expanding it to include JS, and calling it an enhancement request.
It seems to me that an enhancement allowing transform profiles to feed Number and Number:UoM Items would be a useful enhancement.
For those bindings not directly supporting transforms, the uses of SCALE for e.g. sensor readings are obvious. The greater flexibility of JS would allow parsing of numeric values from text, translation of units to OH standards e.g. "99 kilowatts" to "99 | kW", and even adding units where known but not sent in the data.
Equivalent functionality to postUpdate?
Unrelated issue really, but a means of logging transform profile errors would be an advantage.
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.
tsmit
(Tom Smit)
March 5, 2020, 10:27pm
4
Ah, yeah that’s what I thought also but I wasn’t a 100% sure…
4est
(Dan Padure)
March 6, 2020, 6:01pm
5
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
4est
(Dan Padure)
March 6, 2020, 6:02pm
6
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)
kriznik
(kriznik)
March 6, 2020, 6:10pm
7
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.
4est
(Dan Padure)
March 6, 2020, 6:11pm
8
sounds good enough, thanks
4est
(Dan Padure)
March 6, 2020, 6:28pm
9
I tried:
Switch heatingstatus_mant1 "status test [MAP(tasmotacontact.map):%s]" <radiator> (E2_Hol) { channel="mqtt:topic:nodemcu-v3-mansarda:heatingstatus-man8", expire="15m"}
4est
(Dan Padure)
March 6, 2020, 6:32pm
10
I can autoupdate=“false”, this makes it only change in UI, but I would like it not to do even that
4est
(Dan Padure)
March 6, 2020, 6:36pm
11
I can show it as text item in sitemap, this way it can’t be clicked
kriznik
(kriznik)
March 7, 2020, 9:17am
12
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
1 Like