Tasmota RGB convert to Hex

I’ve been searching the forums and documentation for a couple hours but cannot find a solution. Tasmota requires (at least to the best of my knowledge) any solid color change to be submitted in HEX format but is appears HA requires (xxx,xxx,xxx) format. For reference I have a ws2812 strip connected to a wemos D1 mini. I can change schemes, change dimmer levels etc from within HA I just cannot change the color. If I manually use the Tasmota “console” I can change the color.

In short, is there a module or script or anything that can help send colors in HEX.

Even if I was able to create a static color list of say a dozen colors that would be fine. Just like the “effects_list” option a color_list would do just fine.

thanks

bump. anyone!

rgb_command_template: "{{ ‘%02x%02x%02x’ | format(blue, green, red)}}"

Add that into your light mqtt config and try it. Works for me with tasmota on a wemos d1 mini ws2813 strip.

3 Likes

Thanks. I stumbled across that as well. PS: my light buld in the UI changes color when I use the color picker so the data is there somewhere. The frustrating part is that was added to HA more than 2 weeks ago and I saw this command 2 weeks ago. Not bashing HA, but the documentation on this is absolutely horrible…

“rgb_command_template (Optional): Defines a template to compose message which will be sent to rgb_command_topic. Available variables: red, green and blue.”

Maybe I just don’t understand templates, but how was I supposed to understand I needed '%02x%02x%02x’ with that description.

Generally speaking HA documentation is really good. in fact, much better than most open-source software, but if someone sees this, the documentation is just too generic, too simple. We need better example of how to implement moderately complex stuff. Just my 3 cents. thanks again.

Would you mind sharing your config? I’ve been trying to figure this out for days

- platform: mqtt
  name: Garage Status Light
  effect_list:
      - 0
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      - 10
      - 11
      - 12
  state_topic: "cmnd/sonoffsv/power2"
  command_topic: "cmnd/sonoffsv/power2"
  brightness_state_topic: "cmnd/sonoffsv/Dimmer"
  brightness_command_topic: "cmnd/sonoffsv/Dimmer"
  brightness_scale: 100
  rgb_command_template: "{{ '%02x%02x%02x' | format(red, green, blue)}}"
  rgb_state_topic: "cmnd/sonoffsv/Color"
  rgb_command_topic: "cmnd/sonoffsv/Color"
  effect_command_topic: "cmnd/sonoffsv/Scheme"
  effect_state_topic: "cmnd/sonoffsv/Scheme"
 state_value_template: "{{ value }}"
  brightness_value_template: "{{ value }}"
  effect_value_template: "{{ value }}"
  rgb_command_mode: hex
  retain: false
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
1 Like

Thank you for that you saved me some major headaches. I was also wondering how you exposed the color, dimmer and scheme controls in HA?

- platform: mqtt
  name: Office Leds
  state_topic: "stat/OfficeLed/POWER"
  command_topic: "cmnd/OfficeLed/POWER"
  rgb_state_topic: "stat/OfficeLed/RESULT"
  rgb_value_template: "{{ value_json.Color }}"
  rgb_command_topic: "cmnd/OfficeLed/COLOR"
  brightness_state_topic: "stat/OfficeLed/RESULT"
  brightness_command_topic: "cmnd/OfficeLed/DIMMER"
  brightness_scale: 100
  brightness_value_template: "{{ value_json.Dimmer }}"
  qos: 0
  optimistic: false
  retain: true
  effect_state_topic: "stat/OfficeLed/SCHEME"
  effect_command_topic: "cmnd/OfficeLed/SCHEME"  
  effect_value_template: "{{ value_json.scheme }}"  
  effect_list:
      - 0
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      - 10
      - 11
      - 12
  payload_on: "ON"
  payload_off: "OFF"

This is what i have. Also i set SetOption15 ON in the console.

1 Like

Awesome. I finally got some time to sit down and get this working. Thanks for the help guys.

neither of these configuration snippets are working for me, impossible to select a color from the picker.
On, Off & Dimmer work fine though.
There’s many many errors in the log.
Can some one please confirm ??

It works perfectly for me I don’t see any errors regarding the lights.

1 Like

@Beef-well would you mind pasting yr relevant config for the h801 please? Also, confirm you can pick a color from the rgb wheel, you seem to say that On, Off & Dimmer work - but you do not mention the color picker ?

I used the config that Oriolism posted above. Sounds like your RGB state topic isn’t quite right.

I updated Tasmota to 5.12 (from 5.11.1), now the color picker works.
There is still a bucketload of errors in the home assistant log, so definately something is still off.

Would some one please have a look at their log when selecting colors ?

I get
Error doing job: Exception in callback <function async_subscribe.<locals>.async_mqtt_topic_subscriber at 0x7f93c3735c80> 11:13 AM components/light/mqtt.py (ERROR)
when I select a color, but everything still works.

that’s only a tiny part of what is really added to the log :

Feb 14 17:21:27 home hass[7258]: 2018-02-14 17:21:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=rgb_color=[255, 255, 255], entity_id=light.tasmotav4, service=turn_on, service_call_id=139957415675720-333, domain=light>
Feb 14 17:21:27 home hass[7258]: 2018-02-14 17:21:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=139957415675720-333>
Feb 14 17:21:27 home hass[7258]: 2018-02-14 17:21:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=topic=cmnd/h801/COLOR, retain=True, payload=255,255,255, qos=0, service=publish, service_call_id=139957415675720-334, domain=mqtt>
Feb 14 17:21:27 home hass[7258]: 2018-02-14 17:21:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=topic=cmnd/h801/POWER, retain=True, payload=ON, qos=0, service=publish, service_call_id=139957415675720-335, domain=mqtt>
Feb 14 17:21:27 home hass[7258]: 2018-02-14 17:21:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=139957415675720-334>
Feb 14 17:21:27 home hass[7258]: 2018-02-14 17:21:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=139957415675720-335>
Feb 14 17:21:27 home hass[7258]: 2018-02-14 17:21:27 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/h801/RESULT’, b’{“POWER”:“ON”}‘, 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225
Feb 14 17:21:27 home hass[7258]: Traceback (most recent call last):
Feb 14 17:21:27 home hass[7258]: File “/usr/lib/python3.5/asyncio/events.py”, line 126, in _run
Feb 14 17:21:27 home hass[7258]: self._callback(*self._args)
Feb 14 17:21:27 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py”, line 244, in async_mqtt_topic_subscriber
Feb 14 17:21:27 home hass[7258]: hass.async_run_job(msg_callback, dp_topic, payload, dp_qos)
Feb 14 17:21:27 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 253, in async_run_job
Feb 14 17:21:27 home hass[7258]: target(*args)
Feb 14 17:21:27 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/mqtt.py”, line 248, in brightness_received
Feb 14 17:21:27 home hass[7258]: device_value = float(templatesCONF_BRIGHTNESS)
Feb 14 17:21:27 home hass[7258]: ValueError: could not convert string to float:
Feb 14 17:21:27 home hass[7258]: 2018-02-14 17:21:27 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/h801/RESULT’, b’{“POWER”:“ON”}‘, 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225
Feb 14 17:21:27 home hass[7258]: Traceback (most recent call last):
Feb 14 17:21:27 home hass[7258]: File “/usr/lib/python3.5/asyncio/events.py”, line 126, in _run
Feb 14 17:21:27 home hass[7258]: self._callback(*self._args)
Feb 14 17:21:27 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py”, line 244, in async_mqtt_topic_subscriber
Feb 14 17:21:27 home hass[7258]: hass.async_run_job(msg_callback, dp_topic, payload, dp_qos)
Feb 14 17:21:27 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 253, in async_run_job
Feb 14 17:21:27 home hass[7258]: target(*args)
Feb 14 17:21:27 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/mqtt.py”, line 267, in rgb_received
Feb 14 17:21:27 home hass[7258]: templatesCONF_RGB.split(’,‘)]
Feb 14 17:21:27 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/mqtt.py”, line 266, in
Feb 14 17:21:27 home hass[7258]: self._rgb = [int(val) for val in
Feb 14 17:21:27 home hass[7258]: ValueError: invalid literal for int() with base 10: ‘’
Feb 14 17:21:27 home hass[7258]: 2018-02-14 17:21:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: message=Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/h801/RESULT’, b’{“POWER”:“ON”}‘, 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225, timestamp=1518625287.4504366, level=ERROR, exception=Traceback (most recent call last):
Feb 14 17:21:27 home hass[7258]: File “/usr/lib/python3.5/asyncio/events.py”, line 126, in _run
Feb 14 17:21:27 home hass[7258]: self._callback(*self._args)
Feb 14 17:21:27 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py”, line 244, in async_mqtt_topic_subscriber
Feb 14 17:21:27 home hass[7258]: hass.async_run_job(msg_callback, dp_topic, payload, dp_qos)
Feb 14 17:21:27 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 253, in async_run_job
Feb 14 17:21:27 home hass[7258]: target(*args)
Feb 14 17:21:27 home hass[7258]: File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/mqtt.py”, line 248, in brightness_received
Feb 14 17:21:27 home hass[7258]: device_value = float(templatesCONF_BRIGHTNESS)
Feb 14 17:21:27 home hass[7258]: ValueError: could not convert string to float:
Feb 14 17:21:27 home hass[7258]: , source=components/light/mqtt.py>
Feb 14 17:21:27 home hass[7258]: 2018-02-14 17:21:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: message=Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/h801/RESULT’, b’{“POWER”:“ON”}', 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225, timestamp=1518625287.4558733, level=ERROR, exception=Traceback (most recent call last):
Feb 14 17:21:27 home hass[7258]: File “/usr/lib/python3.5/asyncio/events.py”, line 126, in _run

But sure enough, it still works…:roll_eyes: