openhab-addons icon indicating copy to clipboard operation
openhab-addons copied to clipboard

[jinja] Allow adding jinja extensions

Open danieldemus opened this issue 1 year ago • 1 comments

I have been trying to set up an AMS reader to submit power readings to openhab via mosquitto.

AMS Reader can provide Home Assistant discovery. Unfortunately all the discovered channels contain a value template along the lines of "val_tpl":"{{ value_json.P3 | is_defined }}". "is_defined" is a HA extension to jinja, so all channels fail when receiving data with: "Executing the JINJA-transformation failed: An error occurred while transformation. UnknownTokenException: Unknown token found: value_json.P3 | is_defined".

There is a list of these extensions at https://www.home-assistant.io/docs/configuration/templating/.

To be able to implement these extensions in the mqtt.homeassistant binding, you need to be able to add java implementations of jinja extensions.

jinjava supports adding custom extensions that implement given interfaces on the Context class, so the main thing missing is a facility in the JinjaTransformationService, or similar place, to read something from f.x. feature.xml for a binding and instantiate and register extensions when constructing the service.

Your Environment

  • Version used: 4.x

So far this is a somewhat nebulous request submitted to start a discussion.

danieldemus avatar Aug 07 '23 22:08 danieldemus

This would be a nice addition. OpenMQTTGateway current works around this issue by having separate compatibility mode for openHAB:

https://github.com/1technophile/OpenMQTTGateway/blob/2645928dbdc4033ce85abb506789a515052ea35a/main/ZmqttDiscovery.ino#L298

(More info https://github.com/1technophile/OpenMQTTGateway/pull/1658)

ssalonen avatar Apr 14 '24 18:04 ssalonen