If you just start reading, jump to Mqtt light default schema for Shelly RGBW2 (RGBW and CCT) - #9 by maxym for solution.
Hello. I’m trying to prepare myself to migrate from mqtt light schema: template
to schema default
.
I’m doing some experiments but so far stuck.
I suppose the hook is hidden in the fact that the received values template must result in a form declared for command. This is how I understand this part of the documentation:
The whole association between data to send and data received seems to be illogical to me. But beyond that, I really don’t understand the last sentence.
I need to be able to send the following json when turning the device:
payload_on: >
{"turn": "on"}
payload_off: >
{"turn": "off"}
At the same time I have to parse state from another topic that contain another json:
{
"ison":true,
"source":"mqtt",
"has_timer":false,
"timer_started":0,
"timer_duration":0,
"timer_remaining":0,
"mode":"color",
"red":22,
"green":233,
"blue":0,
"white":0,
"gain":100,
"effect":0,
"transition":0,
"power":17.24,
"overpower":false
}
As you can see ison
attribute is boolean.
Anyway even if I think I know what is required, it doesn’t work. Here is my complete snipet I’m working on.
Here is a code:
pck_hallways_lights:
mqtt:
light:
- name: "Hall Floor X"
command_topic: "shellies/light-hall2/color/0/set"
state_topic: "shellies/light-hall2/color/0/status"
rgbw_state_topic: "shellies/light-hall2/color/0/status"
brightness_state_topic: "shellies/light-hall2/color/0/status"
availability_topic: "shellies/light-hall2/online"
payload_available: "true"
payload_not_available: "false"
retain: false
qos: 1
rgbw_command_template: >
{
"red": red
,"green": green
,"blue": blue
,"white": white
}
brightness_command_template: >
{
"gain": {{ value | float | multiply(0.3922) | round(0) }}
}
payload_on: >-
{"turn": "on"}
payload_off: >-
{"turn": "off"}
state_value_template: >-
{% if value_json.ison %}{"turn": "on"}
{% else %}{"turn": "off"}
{% endif %}"
brightness_value_template: "{{ value_json.gain | float | multiply(2.55) | round(0) }}"
rgbw_value_template: "5,100,3,50"
I hardcoded values for rgbw_value_template
just to make sure I’m not making mistake in decoding those values.
The result:
The light is not recognized as a light. Rather as a switch instead.
It’s not able to react to device state changes. But it’s able to send on/off commands to the device properly.
I did experiment with hardcoding all three attributes listed below in order to find root cause.
payload_on: on
payload_off: off
state_value_template: on
The created entity is recognized as light. If so, I don’t understand why my code above doesn’t work. Maybe it’s related to yaml syntax or so.
Hope someone will be able to shed a bit of light.
Other issue which I found is that using schema: default
for this type of mqtt light ends with error:
Invalid config for [mqtt]: not a valid value for dictionary value @ data['mqtt']['light'][7]['schema'].
Got 'default'. (See /config/configuration.yaml, line 31).
regardless what is stated in the documentation.