Im just put together a custom milight hub (https://github.com/sidoh/esp8266_milight_hub)
Now i want to use one of my milight remotes to control more than just the milights directly but also other stuff arround my flat.
This is possible using a little automation as the hub picks up every signal from the remote and publishes it to mqtt. HA will pick this up and forward it to the right light.
I can now control my rgbw light this way even tho it is not paired with this remote.
Only one Problem, as this is RGBW and not RGB_CCT the color_temp command wont trigger my bulb into white mode, this only works by using another command.
So my plan is if the trigger payload looks like {“color_temp”:123} it should replace the payload and if not just forward the original payload.
It won’t work because jinja cannot output complex objects like dictionaries and lists. It’s outputting them as a string and the interpreter is keeping it a string.
You should always pull the information out of the payload or populate it with default. I don’t know what’s in your payload so this code will probably not work for you:
payload_template:
command: >
{% if 'color_temp' in trigger.payload %}
{{ trigger.payload.color_temp }}
{%- else -%}
set_white
{%- endif %}
I’m surprised that works to be honest. Usually that syntax would return an error. I’m gonna have to investigate this. It doesn’t make sense that you can output a json dict using templating.
I’m not sure that matters. The templating has been pretty solid for a while. I’m wondering if I’ve been steering people wrong because I made a mistake in the past or if payload_templates are unique. Either way, I need to investigate.
I ran some tests and talked with some people, this only works because MQTT is parsing the string properly when reading the payload. This will not work for other templates. Just keep that in mind when you create other automations.