openhab-addons: [mqtt.homeassistant][JINJA] Transformation problem with value template key

I did read this is potentially the wrong place (just need some feedback at this point). I’m not fluent in Java but can read a little bit of code. The actual log message is from the Addons repository, but when I looked into that class it appears to call on the transformation services in the core. However, from within the core I could not find the source.

Background: I’m experimenting with zwave-js-ui for OH. On a test system I can discover all my test zwave devices in OH4M3. Test setup with openhabian (on WSL - Debian 11 with MQTT, Json Path & Jinja transform installed) and all the channels/topics appear. It is early in testing so far, but most channels/topics can be linked to items and display the state (ON/OFF or Number).

The one type of channel /topic with a problem so far; {"value_template":"{{ {22: \"Window/door is open\",23: \"Window/door is closed\",5632: \"Window/door is open in regular position\",5633: \"Window/door is open in tilt position\"}[value_json.value] | default(value_json.value) }}","icon":"mdi:alarm-light","state_topic":"zwave/nodeID_10/113/0/Access_Control/Door_state","json_attributes_topic":"zwave/nodeID_10/113/0/Access_Control/Door_state","device":{"identifiers":["zwavejs2mqtt_0xe2bd1ff1_node10"],"manufacturer":"Zooz","model":"Tilt Shock XS Sensor (ZSE43)","name":"nodeID_10","sw_version":"1.20.1"},"name":"nodeID_10_notification_access_control_door_state","unique_id":"zwavejs2mqtt_0xe2bd1ff1_10-113-0-Access_Control-Door_state"}

Expected Behavior

I would hope this should return the string corresponding with the number. I don’t know if this is a bug or just not allowed by the Jinja /JSON specification.

Current Behavior

2023-06-27 14:32:56.534 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. InterpretException: Error resolving expression [{22: "Window/door is open",23: "Window/door is closed",5632: "Window/door is open in regular position",5633: "Window/door is open in tilt position"}[value_json.value] | default(value_json.value)]: TemplateStateException: Dict key must be a string or identifier, was: 22

and another; 2023-06-27 14:32:56.174 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JINJA-transformation failed: An error occurred while transformation. InterpretException: Error resolving expression [{0: "off", 1: "heat", 2: "cool"}[value_json.value] | default('off')]: TemplateStateException: Dict key must be a string or identifier, was: 0

Possible Solution

Allow a number to be the index to get the string. If it helps, all the numbers will be a member of integers.

Context

zwave-js-ui includes several features not currently available with the OH Zwave binding including S2 security, OTA firmware updates, 700/800 series controllers and has applied for certification with the Zwave Alliance standards body. I do not know if this is going to work. There could be more issues (possibly impossible to resolve) as I add different devices.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Hi Robert,

let’s start a discussion in the openhab forum. I totally agree to your vision of making zwave-js-ui the guy, who connects OH to the devices. But we definitely need autodiscovery. IMO all devices listed in https://devices.zwave-js.io should work out of the box. So I guess we need a bridge. zwave-js-ui has a REST and a WebSocket API, which might be useful. As far as I understood it’s providing a “Home Assistant Backend API”.

I’m willing to implement such a bridge though I’m completely new to OH. But I need it. I bought a 700 stick and want it to work in OH.