You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, my journey landed to this plugin however looking through the code, some changes are necessary.
I'm trying to control ZigBee power socket plug (a variation of this device) which operates like (lets imagine a friendly name as z2m/device/id1):
publishes into topic z2m/device/id1 with payload like {"child_lock":"UNLOCK","current":0,"energy":0.04,"indicator_mode":"off/on","last_seen":"2023-11-10T22:53:42.395Z","linkquality":200,"power":0,"power_outage_memory":"restore","state":"ON","update":{"installed_version":192,"latest_version":192,"state":"idle"},"update_available":null,"voltage":241}
can receive for ex. power switch command via JSON payload like {"state":"ON"} published to topic z2m/device/id1/set
So I was trying to force this plugin to work with this setting (it doesn't work!):
Using it as a switch
Subscribed topic: z2m/device/id1
JSONata: state = "OFF" ? {"state":"OFF"}:{"state":"ON"}
OFF message: {"state":"OFF"}
ON message: {"state":"ON"}
Publish topic: z2m/device/id1/set
I'm able either:
receiving properly the current state -> JSONata expression evaluation from topic works with a simple expression like state and mapping to simple string value (OFF, ON) or e.g. transforming the state to Bool and use false/true as their values
click triggers sending proper JSON payload to publishing topic (based on cfg.) however showed status isn't synced with the real state
unfortunately both don't work together.
I went through the code (I'm not expert on TypeScript nor JSONata) however I feel the issue lies around here where simple toString() is used instead of JSON.stringify(...).
My basic test:
var json = JSON.parse('{"child_lock":"UNLOCK","current":0,"energy":0.04,"indicator_mode":"off/on","last_seen":"2023-11-10T21:49:11.520Z","linkquality":204,"power":0,"power_outage_memory":"restore","state":"ON","update":{"installed_version":192,"latest_version":192,"state":"idle"},"update_available":null,"voltage":240}');
console.log("json: " + JSON.stringify(json));
var expression = jsonata('state = "OFF" ? {"state":"OFF"}:{"state":"ON"}')
var result = await expression.evaluate(json);
console.log("\nresult (toString): " + result.toString());
console.log("result (stringify): " + JSON.stringify(result));
console.log("------");
var expression2 = jsonata('state')
var result2 = await expression2.evaluate(json);
console.log("result (toString): " + result2.toString());
console.log("result (stringify): " + JSON.stringify(result2));
produces this output:
json: {"child_lock":"UNLOCK","current":0,"energy":0.04,"indicator_mode":"off/on","last_seen":"2023-11-10T21:49:11.520Z","linkquality":204,"power":0,"power_outage_memory":"restore","state":"ON","update":{"installed_version":192,"latest_version":192,"state":"idle"},"update_available":null,"voltage":240}
result (toString): [object Object]
result (stringify): {"state":"ON"}
------
result (toString): ON
result (stringify): "ON"
so as you can see a more complex evaluation (like my first test) can't be simply converted to String via result.toString() but JSON.stringify(result) produces a result which can be compared with ON/OFF values and makes sense...
The text was updated successfully, but these errors were encountered:
Hi, my journey landed to this plugin however looking through the code, some changes are necessary.
I'm trying to control ZigBee power socket plug (a variation of this device) which operates like (lets imagine a friendly name as
z2m/device/id1
):z2m/device/id1
with payload like{"child_lock":"UNLOCK","current":0,"energy":0.04,"indicator_mode":"off/on","last_seen":"2023-11-10T22:53:42.395Z","linkquality":200,"power":0,"power_outage_memory":"restore","state":"ON","update":{"installed_version":192,"latest_version":192,"state":"idle"},"update_available":null,"voltage":241}
{"state":"ON"}
published to topicz2m/device/id1/set
So I was trying to force this plugin to work with this setting (it doesn't work!):
Using it as a switch
Subscribed topic:
z2m/device/id1
JSONata:
state = "OFF" ? {"state":"OFF"}:{"state":"ON"}
OFF message:
{"state":"OFF"}
ON message:
{"state":"ON"}
Publish topic:
z2m/device/id1/set
I'm able either:
state
and mapping to simple string value (OFF
,ON
) or e.g. transforming the state to Bool and use false/true as their valuesunfortunately both don't work together.
I went through the code (I'm not expert on TypeScript nor JSONata) however I feel the issue lies around here where simple
toString()
is used instead ofJSON.stringify(...)
.My basic test:
produces this output:
so as you can see a more complex evaluation (like my first test) can't be simply converted to String via
result.toString()
butJSON.stringify(result)
produces a result which can be compared with ON/OFF values and makes sense...The text was updated successfully, but these errors were encountered: