Hi everybody,
I have a WS2812
led strip hooked up to a nodeMCU
running tasmota
, which I have included in my home-assistant. My current configuration for it looks like this
- name: "Schlafzimmer LED"
command_topic: "cmnd/tasmota-5909/POWER"
brightness_command_topic: "cmnd/tasmota-5909/dimmer"
rgb_command_topic: "cmnd/tasmota-5909/color"
availability_topic: "tele/tasmota-5909/LWT"
state_topic: "tele/tasmota-5909/STATE"
state_value_template: "{{ value_json.POWER }}"
brightness_state_topic: "tele/tasmota-5909/STATE"
brightness_value_template: "{{ value_json.Dimmer }}"
rgb_state_topic: "tele/tasmota-5909/STATE"
rgb_value_template: "{{ value_json.Color }}"
hs_state_topic: "tele/tasmota-5909/STATE"
hs_value_template: "{{ value_json.HSBColor }}"
effect_command_topic: "cmnd/tasmota-5909/scheme"
#effect_value_template: >
# "{% if }
# "
effect_list:
- "0"
- "1"
- "12"
<<: &led_template
platform: mqtt
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
qos: 2
retain: false
It works fine¹ so far. I can control colors and toggle it’s status. However, I cannot figure out how to create a readable list for the effects. Tasmota expects a payload sent to cmnd/<tasmota>/scheme
from 0 to 12. This current solution I have works. If I click 12, I’ll get the “fire” pattern. These are some possible options
6 = candlelight pattern
7 = RGB pattern
8 = Christmas pattern
9 = Hannukah pattern
10 = Kwanzaa pattern
11 = rainbow pattern
12 = fire pattern
My goal is to have a list containing these strings, and if one of those strings matches, to submit the appropriate payload via mqtt (click “rainbow pattern”, submit payload 11
).
I am not sure how to structure the template, though. I’ll need something like
{% if <what_goes_here_?> == "Hannukah pattern" %}
return "9"
{%elif <what_goes_here_?> == "Christmas pattern" %}
return "8"
(etc.)
{% endif %}
Correct? I just don’t know what variable I am supposed to for <what_goes_here_?>
; also, I am a beginner when it comes to jina2
and home-assistant in general, but I assume it might be able to just use a dictionary instead of a whole bunch of if statements… is this correct? And if so, how can I implement it?
Since I don’t know the actual way to do this, let’s assume I declare these keys and values (json in this example)
{ "schemes": {
"rainbow pattern": "11",
"fire pattern": "12"}
#(etc.)
}
and then an if statement that will see if any submitted value fits the dictionary, and if so, submits the value instead of the key…?
¹ this particular device started automatically turning on soon after being turned off on it’s own. This can happen within 10 seconds or a few minutes (haven’t figured out the exact period and whether or not it is always the same). I have retain set to false in home-assistant, but powerretain
set to 1
in tasmota; however, when I turn this off in tasmota, home-assistant will not recognize the current state (let’s say I turn the device off in home-assistant; then it will actually turn off, but the switch will go right back to on).
Thanks in advance for your help