I am at a real lose right now. I have setup a light bulb with ESPHome using MQTT instead of the API. I can get the light working using the JSON schema but I really need to be able to use the template schema. In doing so anytime I try to input the state_template it isn’t getting any information back from my MQTT and the switch in Home assistant just shuts right back off but the light will turn on.
My setup:
Home Assistant 0.99.3 running in a docker on unRAID
ESPHome running in a docker on unRAID (latest version)
MQTT running in a docker on unRAID (latest version)
The reason I am wanting to use the template schema is, so I can hopefully make it where the white value turns all the way down when rgb has a value less then 255 and have it turn back up when they are all at 255.
2019-10-03 08:08:33 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on LB_OfficeMainLight2/stat (retained): b'{"state":"ON","brightness":1,"color":{"r":255,"g":0,"b":0},"white_value":211}'
2019-10-03 08:08:33 WARNING (MainThread) [homeassistant.components.mqtt.light.schema_template] Invalid state value received
I’m not sure why it is thinking it is invalid since the returned message should either be “ON” or “OFF”
In the documentation, there’s an example containing the following comment:
# must return `on` or `off`
It seems it is upper-case for most other MQTT components like binary_sensors and switches and even the default light but here, for the template schema, it’s suggesting it is lower-case.
My setting is a bit different, but I also have a problem with a template in an MQTT light.
I want to control Dali lights from HA via an MQTT-Dali Gateway. I can control the Dali lights, but I do not get an update in HA of the actual state of the Dali lights (needed since the Dali lights can also be controlled outside of HA via some Dali controllers).
I have a problem with templates on state and brightness. The state JSON payload does not contain an actual state. I need to calculate the state based on brightness. If brightness is 0, state is “off”. Otherwise it’s “on”.
Logger: homeassistant.components.mqtt.light.schema_template
Source: components/mqtt/light/schema_template.py:173
Integration: MQTT (documentation, issues)
First occurred: 9:46:07 PM (1 occurrences)
Last logged: 9:46:07 PM
Invalid state value received
Logger: homeassistant.helpers.template
Source: helpers/template.py:1791
First occurred: 9:46:07 PM (2 occurrences)
Last logged: 9:46:07 PM
Template variable error: ‘value_json’ is undefined when rendering ‘{%- if value_json.brightness == 0 -%} off {%- else -%} on {%- endif -%}’
Template variable error: ‘value_json’ is undefined when rendering ‘{{ value_json.brightness }}’
Logger: homeassistant.helpers.template
Source: helpers/template.py:574
First occurred: 9:46:07 PM (2 occurrences)
Last logged: 9:46:07 PM
Error parsing value: ‘value_json’ is undefined (value: { “brightness”: 234, “channel”: 15,}, template: {%- if value_json.brightness == 0 -%} off {%- else -%} on {%- endif -%})
Error parsing value: ‘value_json’ is undefined (value: { “brightness”: 234, “channel”: 15,}, template: {{ value_json.brightness }})
Logger: homeassistant.components.mqtt.light.schema_template
Source: components/mqtt/light/schema_template.py:183
Integration: MQTT (documentation, issues)
First occurred: 9:46:07 PM (1 occurrences)
Last logged: 9:46:07 PM
Invalid brightness value received