zwave-js / zwave-js-ui

Full featured Z-Wave Control Panel UI and MQTT gateway. Built using Nodejs, and Vue/Vuetify
https://zwave-js.github.io/zwave-js-ui
MIT License
970 stars 204 forks source link

[bug] Add default on all HA templates for attributes #1020

Closed drjjr2 closed 3 years ago

drjjr2 commented 3 years ago

Version

Checklist:

Build/Run method

zwavejs2mqtt version: 3.2.0 zwave-js version: 7.1.1

Describe the bug

Similar to the issue for zigbee2mqtt described here

To Reproduce

Steps to reproduce the behavior:

  1. start zwave2jsmqtt
  2. home_assistant.log shows lots of WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ {}[value_json.value] | default(value_json.value) }}' and WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ value_json.value}}'

Expected behavior

There should not be warnings.

Additional context

Add any other context about the problem here.

robertsLando commented 3 years ago

hummm that's strange, I mean the warning is strange, has this been introduced in a recent update? If so what kind of payload type are you using? Just value or Json time value or entire zwave object?

drjjr2 commented 3 years ago

I am using the entire zwave object. And, yes, this just started with the 2021.4.0 update yesterday.

robertsLando commented 3 years ago

@drjjr2 The fix is not that easy to do, we should firstly detect for each device why that field is missing... Check the discussion on the PR you linked

drjjr2 commented 3 years ago

OK, I'll try to do some digging. The HA logs don't give me any indication of which device is causing the warning.

robertsLando commented 3 years ago

Thanks! Let me know

drjjr2 commented 3 years ago

OK, so I can see this happening when I have a GE 14291 light switch. The node interview shows it has

switch_switch   switch  switch  Yes Enabled
sensor_scene_state_sceneid  sensor  scene_state_sceneid Yes Enabled
sensor_scene_state_dimmingduration  sensor  scene_state_dimmingduration Yes Enabled

But sceneid and dimmingduration are unknown. In fact, it's not even a dimmable switch. I modified the JSON to include extra spaces before the }} and could see them show up in the log.

2021-04-12 18:11:57 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ value_json.value   }}'
2021-04-12 18:11:59 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ value_json.value  }}'
2021-04-12 18:12:00 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ value_json.value   }}'

My guess is every switch that has those sensors that aren't reporting anything are causing this error.

robertsLando commented 3 years ago

I think this may be related to https://github.com/zwave-js/zwavejs2mqtt/issues/1020 , can you tell your payload type settings?

drjjr2 commented 3 years ago

I think this may be related to #1020 , can you tell your payload type settings?

Yes, I submitted #1020. This is more information that I am finding. The payload is the entire zwave object.

robertsLando commented 3 years ago

LOL this is #1020, sorry 😆 Are you able to see with mqtt explorer what's the payload sent there? I think this could be due to the "value" property set to undefined in some cases

drjjr2 commented 3 years ago

OK, I'm no MQTT expert but in HA if I look at the last message received for sceneid, there is no "value" in the JSON:

homeassistant/Garage_Light/43/0/sceneId
Received 10:15:00 PM
QoS: 0, Retained
Payload: {
  "id": "22-43-0-sceneId",
  "nodeId": 22,
  "commandClass": 43,
  "commandClassName": "Scene Activation",
  "endpoint": 0,
  "property": "sceneId",
  "propertyName": "sceneId",
  "type": "number",
  "readable": true,
  "writeable": true,
  "label": "Scene ID",
  "stateless": false,
  "min": 1,
  "max": 255,
  "list": false,
  "lastUpdate": 1618264281471
}
robertsLando commented 3 years ago

Yeah that's what I mean, I think that we could convert undefined fields to null or maybe just ignore undefined values

drjjr2 commented 3 years ago

Looks like the zigbee2mqtt folks decided on null: Home Assistant: set unknown values to null #6987 #7032

frenck commented 3 years ago

I think that we could convert undefined fields to null or maybe just ignore undefined values

There is a difference. Missing should be unexpected, while a null value is there but unknown. Defaulting to null, kinda defeats the purpose of the change in Home Assistant.

drjjr2 commented 3 years ago

I haven't looked at all the devices that are causing the warnings that I am seeing, but at least in the case of the GE 14291, it has a dimming duration that shouldn't even apply to it (it's not a dimming switch). I guess sceneid should report null if no scene has been activated on it.

towerhand commented 3 years ago

Yea, out of the 4 entitites in my GE switches only 2 have "value_template": "{{ value_json.value}}" in the discovery payload. ("sensor_scene_state_dimmingduration" and "sensor_scene_state_sceneid")

All entities in zooz and inovelli switches I own have "value_template": "{{ value_json.value}}" in the discovery payload.

Yale lock too, except two entities that have "value_template": "{{ {}[value_json.value] | default(value_json.value) }}" which also shows a warning in HA.

This is the full Hass device JSON for one of my switches. Any other recommendations @frenck


{
  "type": "switch",
  "object_id": "switch",
  "discovery_payload": {
    "payload_off": false,
    "payload_on": true,
    "value_template": "{{ value_json.value }}",
    "command_topic": "zwave2jsmqtt/dining_room_lights/37/0/targetValue/set",
    "state_topic": "zwave2jsmqtt/dining_room_lights/37/0/currentValue",
    "device": {
      "identifiers": [
        "zwavejs2mqtt_0xead969cf_node7"
      ],
      "manufacturer": "Inovelli",
      "model": "In-Wall Switch (On/Off) Scene Enabled (NZW30S)",
      "name": "dining_room_lights",
      "sw_version": "1.3"
    },
    "name": "dining_room_lights_switch",
    "unique_id": "zwavejs2mqtt_0xead969cf_7-37-0-currentValue"
  },
  "discoveryTopic": "switch/dining_room_lights/switch/config",
  "values": [
    "37-0-currentValue",
    "37-0-targetValue"
  ],
  "persistent": false,
  "ignoreDiscovery": false,
  "id": "switch_switch"
}
scyto commented 3 years ago

FWIW i have this on 12 devices - all my locks, couple of my odd rgbw devices and in the node ready info - not sure if thats because one if my nodes is off or not. image

robertsLando commented 3 years ago

@scyto you mean you see that warning from 12 devices?

scyto commented 3 years ago

I see one warning per long line above i believe. Logging in hass is less than good at actually telling me.

scyto commented 3 years ago

i lied, I see 36 lines - have yet to prove they are all from mqtt - though multiple issues indicated this to be mostly mqtt related. i guess i could up the logging on mqtt instead? (debug on homeassistant.helpers.template revealed nothing more than what you see below)

image

--edit-- i upped mqtt logging and this shows it is all the zwavejs entries in mqtt, here is sample.

2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to zwavejs2mqtt/Basement/Strip/50/1/previousValue/65537, mid: 326
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to zwavejs2mqtt/Basement/Strip/50/1/previousValue/66049, mid: 327
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/2/deltaTime/66049 (retained): b'{"time":1620010049271,"value":0,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to zwavejs2mqtt/Basement/Strip/50/2/value/65537, mid: 328
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/2/previousValue/66049 (retained): b'{"time":1620010049273,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ value_json.value }}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to zwavejs2mqtt/Basement/Strip/50/2/deltaTime/65537, mid: 329
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to zwavejs2mqtt/Basement/Strip/50/2/value/66049, mid: 330
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/3/value/65537 (retained): b'{"time":1620010049328,"value":4.115,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/3/previousValue/65537 (retained): b'{"time":1620010049329,"value":2.285,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/3/deltaTime/65537 (retained): b'{"time":1620010049330,"value":0,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/3/value/66049 (retained): b'{"time":1620010049332,"value":2.134,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/3/deltaTime/66049 (retained): b'{"time":1620010049333,"value":0,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/3/previousValue/66049 (retained): b'{"time":1620010049335,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ value_json.value }}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/4/value/65537 (retained): b'{"time":1620010049393,"value":0.938,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/4/previousValue/65537 (retained): b'{"time":1620010049394,"value":2.285,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/4/deltaTime/65537 (retained): b'{"time":1620010049396,"value":0,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/4/value/66049 (retained): b'{"time":1620010049397,"value":1.94,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/4/deltaTime/66049 (retained): b'{"time":1620010049398,"value":0,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on zwavejs2mqtt/LivingRoom/Strip/50/4/previousValue/66049 (retained): b'{"time":1620010049401,"nodeName":"Strip","nodeLocation":"LivingRoom"}'
2021-05-03 11:35:47 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ value_json.value }}'

full log file home-assistant.log.txt

drjjr2 commented 3 years ago

I'm fairly certain all (or most) of the errors I have are for the various scene_state_scene_xxx, scene_state_slowrefresh, along with dimming_duration (for some non-dimming switches). I did a dump of all the entities in HA with '' as their state (58 total). Things like alarmlevel for locks that is no longer reported, etc. I'm not sure how to go about reporting which devices are having all of these issues.

robertsLando commented 3 years ago

yeah the problem is that some values are undefined and this is causing the warnings you are seeing there

darootler commented 3 years ago

Any updates here?

I am also seeing this warnings, i do have 52 log entries with the following warning after a Z-Wave JS restart:

2021-06-22 20:28:09 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ value_json.value }}'

Many of them are from the thermostat template i think:

{
  "min_temp": 5,
  "max_temp": 40,
  "temp_step": 0.5,
  "current_temperature_topic": "zwave/Kinderzimmer/Kinderzimmer_Thermostat/49/0/Air_temperature",
  "current_temperature_template": "{{ value_json.value }}",
  "temperature_state_topic": "zwave/Kinderzimmer/Kinderzimmer_Thermostat/67/0/setpoint/1",
  "temperature_state_template": "{{ value_json.value }}",
  "temperature_command_topic": "zwave/Kinderzimmer/Kinderzimmer_Thermostat/67/0/setpoint/1/set",
  "temperature_unit": "C",
  "precision": 0.1,
  "device": {
    "identifiers": [
      "zwavejs2mqtt_0xd563c48f_node17"
    ],
    "manufacturer": "Danfoss",
    "model": "Devolo Thermostat (09356) (MT02650)",
    "name": "Kinderzimmer-Kinderzimmer Thermostat",
    "sw_version": "1.0"
  },
  "name": "Kinderzimmer-Kinderzimmer Thermostat_climate",
  "unique_id": "zwavejs2mqtt_0xd563c48f_Node17_climate"
}

Let me know if i can help.

Regards Richard

jerobins commented 3 years ago

Let me know what I can provide to help. This is my log immediately after HA startup:

Template variable warning: 'dict object' has no attribute 'value' when rendering '{{ value_json.value}}' 3:36:00 PM – (WARNING) helpers/template.py - message first occurred at 3:35:38 PM and shows up 136 times

All from zwavejs2mqtt.

robertsLando commented 3 years ago

Like I said, after a certain hass version hass started complain about undefined fields in payload, not a bid deal, but we could detect the affected values and take the correct approach based on it. Sometimes an undefined value is used to 'reset' a valueId, like for notifications

frenck commented 3 years ago

The question is: Do we even need those entity attributes? A general direction in Home Assistant, is to reduce those attributes as much as possible. (Please note, this comment lack knowledge about the exact content of those attributes).

emichael commented 3 years ago

I'm seeing the same behavior as @drjjr2 with my GE switches, but I'm using the Json Time Value. The scene_state_scene_001 and scene_state_scene_002 sensors (the up and down buttons on the rocker switch) both don't report a value after they're no longer being pressed, so any time you press a button on the switch, you get a new warning in the log.

robertsLando commented 3 years ago

in general any stateless value by default gets an undefined message pèublished to reset the state after an event is received

Andoramb commented 3 years ago

Hm, strange. I still see this on v5.9.0 (was present for some time)

2021-10-15 00:46:28 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_status' when rendering '{{value_json.power_status}}'

I use the platform via the integration in HA only (no mqtt) Having these devices:

Universal Dimmer 500W           FGD211  
Fibargroup  Dimmer 2        FGD212  
Fibargroup  Double Switch 2     FGS223  
Fibargroup  Dimmer 2        FGD212
robertsLando commented 3 years ago

@Andoramb Maybe that is caused by another value sending undefined, like power_status

Andoramb commented 3 years ago

I will check it :) pls ignore my comment for now. will come back if there's anything new/useful. Thanks for your reply :)