-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[jinja] Empty string result when binding is missing #10496
Comments
Also reported to zigbee2mqtt project issue with missing properties in state payload. |
When user-defined transformations are involved, common practice is to chain a REGEX that looks for presence of property to another transformation e.g. JSONPATH extracting property. If the REGEX fails, the JSONPATH is not run and so missing field WARNS and empty updates avoided. |
Sounds like quick fix. These transformations are defined by mqtt topic with Home Assistant configuration, they can be little complexity. Not sure that regexp can be generated to cover jinja syntax. For example: |
I've checked the option com.hubspot.jinjava.JinjavaConfig#isFailOnUnknownTokens. Jinjava 2.5.0 just ignores missing map keys, so we don't know whether state is invalid or empty:
Jinvava 2.5.7 works well:
|
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/update-version-of-osgified-dependency/120768/1 |
…penhab#10578) Signed-off-by: Anton Kharuzhy <antroids@gmail.com> Signed-off-by: John Marshall <john.marshall.au@gmail.com>
…penhab#10578) Signed-off-by: Anton Kharuzhy <antroids@gmail.com>
…penhab#10578) Signed-off-by: Anton Kharuzhy <antroids@gmail.com>
…penhab#10578) Signed-off-by: Anton Kharuzhy <antroids@gmail.com>
…penhab#10578) Signed-off-by: Anton Kharuzhy <antroids@gmail.com>
I'm creating an implementation of climate platform for mqtt.homeassistant binding, but found a side issue.
Variable used in state_template can be missing in the state, but Jinja returns the empty string, that considered as valid value.
Expected Behavior
Thing state should not be updated when variable from state_template is missing in the state.
Current Behavior
20:26:16.995 [WARN ] [hab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.`
Payload:
'{"auto_lock":"AUTO","away_mode":"OFF","away_preset_days":1,"away_preset_temperature":15,"battery_low":false,"boost_time":300,"child_lock":"UNLOCK","comfort_temperature":20,"current_heating_setpoint":20,"eco_temperature":15,"force":"normal","holidays":[{"hour":6,"minute":0,"temperature":20},{"hour":8,"minute":0,"temperature":15},{"hour":11,"minute":30,"temperature":15},{"hour":12,"minute":30,"temperature":15},{"hour":17,"minute":30,"temperature":20},{"hour":22,"minute":0,"temperature":15}],"linkquality":70,"local_temperature":26,"local_temperature_calibration":-1,"max_temperature":35,"min_temperature":5,"position":0,"preset":"schedule","system_mode":"auto","update":{"state":"idle"},"update_available":false,"week":"5+2","window_detection":"OFF","window_detection_params":{"minutes":10,"temperature":5},"workdays":[{"hour":6,"minute":0,"temperature":20},{"hour":8,"minute":0,"temperature":15},{"hour":11,"minute":30,"temperature":15},{"hour":12,"minute":30,"temperature":15},{"hour":17,"minute":30,"temperature":20},{"hour":22,"minute":0,"temperature":15}]}'
Template:
{{ value_json.valve_detection }}
Possible Solution
Try this config option: com.hubspot.jinjava.JinjavaConfig#isFailOnUnknownTokens
Steps to Reproduce (for Bugs)
Your Environment
The text was updated successfully, but these errors were encountered: