Hello, I was wondering which code I have to use for Shelly RGBW2 automations through MQTT
I used this code for adding the LED in HomeAssistant, but which variables do I use to change the brightness value or color? What would the ‘action’ part of an automation look like?
- platform: mqtt
schema: template
name: "LED 1"
command_topic: "shellies/shellyrgbw2-XXXXX/color/0/set"
state_topic: "shellies/shellyrgbw2-XXXXX/color/0/status"
effect_list:
- 0
- 1
- 2
- 3
- 4
- 5
- 6
command_on_template: >
{"turn": "on"
{%- if brightness is defined -%}
, "gain": {{brightness | float | multiply(0.3922) | round(0)}}
{%- endif -%}
{%- if red is defined and green is defined and blue is defined -%}
, "red": {{ red }}, "green": {{ green }}, "blue": {{ blue }}
{%- endif -%}
{%- if white_value is defined -%}
, "white": {{ white_value }}
{%- endif -%}
{%- if effect is defined -%}
, "effect": {{ effect }}
{%- endif -%}
}
command_off_template: '{"turn":"off"}'
state_template: "{% if value_json.ison %}on{% else %}off{% endif %}"
brightness_template: "{{ value_json.gain | float | multiply(2.55) | round(0) }}"
red_template: '{{ value_json.red }}'
green_template: '{{ value_json.green }}'
blue_template: '{{ value_json.blue }}'
white_value_template: '{{ value_json.white }}'
effect_template: '{{ value_json.effect }}'
qos: 2
Sure, it all works perfectly, but I don’t know the syntax for RGBW2 automations.
I jus want to create automations, like when there is movement, there is more brightness, when it’s after 10PM, less brightness, when I watch a movie, the LED gives a different colour, etc
Turn on your light and set to the desired brightness and colour.
Go to the Developer Tools / States page.
Select the entity_id of your light and bask in the glory of all its attributes.
Now go to the Developer Tools / Services page, select light.turn_on from the service drop down box and your lights entity_id from the entity drop down box.
Paste the attributes you copied into the service data field.
Press the CALL SERVICE button and watch for any errors at the bottom of the screen.
They disappear quite quickly so don’t be afraid to spam the call service button until you understand the error.
In my case I was getting errors about too many colour keys, the friendly_name and supported_feature keys, and some others.
I deleted them one by one until there were no more errors and the light turned on.
Select and copy all of your now valid service data.
In the automation editor at the action you want to turn on your light, fill the appropriate info for Action Type, Service and Entities, and paste your service data under Service Data