Thanks David for Posting your config. I have done the same for the availability topic. Wonder though is it will change the status when they become unavailable again due to a power issue… Need to still test this
I do see some errors in Hass to do with extraction of the json response. Haven’t looked into this yet as had no time… do you see the same?
sure will do but away from home ATM
Anyway I see you have used white_value_template and I had for example blue_template… Not sure how the two are different but maybe there is something
I tried your example code for the shelly rgbw2. Everything is working except the effects. The effects are working over the webinterface from the shelly.
This is my code:
- platform: mqtt
schema: template
name: "LEDstrip MQTT"
command_topic: "shellies/shellyrgbw2-5A3BB8/color/0/set"
state_topic: "shellies/shellyrgbw2-5A3BB8/color/0/status"
availability_topic: "shellies/shellyrgbw2-5A3BB8/online"
payload_available: "true"
payload_not_available: "false"
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
Using the command_on_template you have defined, when you change the effect (using the Lovelace UI) this is the payload the template produces:
{"turn": "on", "effect": 4}
Maybe that’s not enough information for the RGBW2? Perhaps it also needs the RGB values as well? I don’t have an RGBW2 so I can’t answer those questions. However, you can easily experiment with the payload’s contents by using Home Assistant’s MQTT Publish page.
It’s faster to use the Publish page to experiment with the payload. Assuming you hit upon the magic combination that makes it work, you can then modify the template to produce the same payload format.
When using this config I am unable to turn the channels on using the regular switch. If I manually set the brightness to 100% it turns on as it should. Any idea how to fix this?
I am referring to the “white mode”, where you can have four separate channels controlling four strips individually, instead of the RGBW-mode. Sorry for being unclear
I have experimented with the effect function on the Shelly RGBW2 over MQTT, I have send all the necessary json data over mqtt to the Shelly. However it seems to be an issue with the Shelly firmware, it’s looks like it is ignoring the effect function.
I posted the question in the Shelly support group on Facebook.
Thanks David. I do not have a Facebook account . Hopefully they will fix it. I also tried many different combinations but none of them did changed the effect.
I started with 123’s code posted above (thanks for that, btw!) but it wasn’t handling brightness at all for me so I did some tweaking. This code improved the situation: I can now properly control brightness when the light is on. However it’s not perfect yet because it doesn’t turn the lights back on at the previous level, even though I can see in MQTT that the it is still stored. As a fallback, this will turn the lights back on at 100%. I’m sure this is due to my inexperience with JSON– this is literally my first attempt at using it.
I’m interested to see how others will improve on this. Thanks in advance!
I offer this minor refinement to help improve clarity (i.e. it doesn’t work any better than what you already have). I’ve tested and it works in the Template Editor (you can copy the two lines into the editor and confirm it for yourself). However, the ultimate test is if it works when part of the RGBW2’s configuration.
command_on_template: >-
{% set x = 100 if brightness is not defined else (brightness|float * 0.3922)|round(0) %}
{"turn":"on", "brightness":{{x}}}
For this refinement, I’m not 100% certain that single-quotes are needed to delimit the last line. You’ll know soon enough by either examining the payload’s appearance using an MQTT client or if the RGBW2 fails to accept the command. If it fails, delimit the last line with single-quotes.
That I finally figured out the retained brightness level on the same day Robert Tait’s video review and matching code dropped on YouTube is a complete coincidence.
Thanks again to all who helped with this. My crown moulding is looking great.
Under the schema: template I don’t see any configuration to handle the red_templateblue_template or green_template but rather rgb_command_topic. Your problem may lie within here.
I have a RGBW2 working and I’ll upload my config for you later. I have each of the RGBW set up as different lights so I have control for each separately.