I control multiple Shelly lights via MQTT. Controlling the lights (on/off & brightness) works without any problem. Getting the state (on/off) also works but getting the current brightness fails. See the warning log warning below:
Logger: homeassistant.components.mqtt.light.schema_template
Source: components/mqtt/light/schema_template.py:218
Integration: MQTT
First occurred: 12:44:25 (3023 occurrences)
Last logged: 21:06:13
Invalid brightness value received
I use the following confguration:
light:
- platform: mqtt
name: 'Light'
unique_id: 'shelly-vintage-xxxxxx'
device:
connections: [["mac", "xx:xx:xx:xx:xx:xx"]]
manufacturer: 'Shelly'
model: 'Shely Vintage ST64'
schema: template
command_topic: 'shellies/ShellyVintage-xxxxxx/light/0/set'
state_topic: 'shellies/ShellyVintage-xxxxxx/light/0/status'
state_template: '{% if value_json.ison %} on {% else %} off {% endif %}'
command_on_template: '{ {% if brightness is defined %}"brightness": {{ brightness / 2.55 }}, {%- endif -%}"turn": "on"}'
command_off_template: '{"turn": "off"}'
brightness_template: '{{ value_json.brightness | float * 2.55 }}'
The payload of on the topic shellies/ShellyVintage-xxxxxx/light/0/status
looks like:
{"ison":true,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"brightness":100}
The brightness range is 0-100. That’s the reason for the * 2.55
(and / 2.55
in the command_on_template
)
I also tried only value_json.brightness
(without ```* 2.55) but that also didn’t work (same warning log).
My current Home Assistant version is 0.117.6 and HassOS 4.15 running on a Raspberry Pi 1B+.
I’m wondering what I’m doing wrong.