New rgb_command_template assistance please

This is the configuration I’ve worked out yesterday. The only thing I’m missing is controlling of WHITE.
Also, errors because of the JSON, probably to fix.

I have RGBW and need to control everything from one switch. I see white slider but it’s value is not send properly.

- platform: mqtt
  name: "LED Salon"
  state_topic: "home/ground/livingroom/ledceiling/stat/POWER"
  command_topic: "home/ground/livingroom/ledceiling/cmnd/POWER"
  availability_topic: "home/ground/livingroom/ledceiling/tele/LWT"
  brightness_state_topic: "home/ground/livingroom/ledceiling/stat/RESULT"
  brightness_command_topic: "home/ground/livingroom/ledceiling/cmnd/Dimmer"
  brightness_scale: 100
  brightaness_value_template: "{{ value_json.Dimmer }}"
  white_value_command_topic: "home/ground/livingroom/ledceiling/cmnd/Color"
  white_value_state_topic: "home/ground/livingroom/ledceiling/stat/RESULT"
  white_value_command_template: "{{ '00000000%02x' | light.led_salon.white_value }}"
  white_value_template: "{{ '00000000%02x' | format(value) }}"
  rgb_command_template: "{{ '%02x%02x%02x0000' | format(green, red, blue)}}"
  rgb_state_topic: "home/ground/livingroom/ledceiling/stat/RESULT"
  rgb_command_topic: "home/ground/livingroom/ledceiling/cmnd/Color"
  rgb_value_template: "{{ '%02x%02x%02x0000' | format(green, red, blue)}}"
  state_value_template: "{{ value_json.state }}"
  retain: true
  qos: 1
  optimistic: false
  payload_on: "on"
  payload_off: "off"
  payload_available: "Online"
  payload_not_available: "Offline"

I’ve done it in other way. Here it is: https://github.com/ardeus-ua/ha-tasmota
That’s custom component made out of inbuilt light/mqtt. Effects list is in readable way, color commands and status work. In case you have any suggestions to the component feel free to list it

@ardeus I like your approach. I’ve imported your python file and setup and setup a test .yaml file and device. running check_config I am getting “Unable to find component light.tasm” Any idea how to troubleshoot this? thx

I’m not sure if check config works for the components that haven’t been loaded yet

simple type’o of the custom_components folder. No issue there, the component loads and no errors in the config. here’s my setup…

Wemos D1 mini
Pin D1 (GPIO 5) set for Tasmota group 07 (ws2812)
In the Tasmota Console I set pixel count using the pixels command

I can manually change the color, dimmer and power in the tasmota console. this all works fine. Here’s what doesn’t work…

If my LED strip is OFF and I use homeassistant to turn on the LED strip, the LED’s turn on. However HA does not recognize that the led is on and immediately sets the light to off in the HA UI yet the LED’s are on. If I use the dimmer slider in the HA UI, this will change the brightness. So we know MQTT is working. Not to mention I have several other devices using MQTT.

Any thoughts?

PS: why are you using POWER1 ? If there is only one switch/device in Tasmota it should just be POWER. just curious. thanks I have tried both Power and Power1

I tailed the log filed when turning on the light and here’s the error… YAML follows

Feb 28 13:43:03 HASS hass[5040]: , source=custom_components/light/tasm.py, message=Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/wstest/RESULT’, b’{“POWER”:“ON”}’, 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225, timestamp=1519843383.7100604, level=ERROR>
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 140277257080560: Received {‘type’: ‘call_service’, ‘service’: ‘turn_on’, ‘domain’: ‘homeassistant’, ‘id’: 24, ‘service_data’: {‘entity_id’: ‘light.wstestled’}}
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=entity_id=light.wstestled, service=turn_on, domain=homeassistant, service_call_id=140278335878032-48>
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=entity_id=[‘light.wstestled’], service=turn_on, domain=light, service_call_id=140278335878032-49>
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=topic=cmnd/wstest/POWER1, qos=0, payload=ON, retain=False, service=publish, domain=mqtt, service_call_id=140278335878032-50>
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/wstest/RESULT: {“POWER”:“ON”}
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/wstest/RESULT’, b’{“POWER”:“ON”}’, 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/wstest/RESULT: {“POWER”:“ON”}
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/wstest/RESULT’, b’{“POWER”:“ON”}’, 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/wstest/RESULT: {“POWER”:“ON”}
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/wstest/RESULT’, b’{“POWER”:“ON”}’, 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225
Feb 28 13:44:03 HASS hass[5040]: , source=custom_components/light/tasm.py, message=Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/wstest/RESULT’, b’{“POWER”:“ON”}’, 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225, timestamp=1519843443.0588367, level=ERROR>
Feb 28 13:44:03 HASS hass[5040]: , source=util/color.py, message=Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/wstest/RESULT’, b’{“POWER”:“ON”}’, 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225, timestamp=1519843443.069422, level=ERROR>
Feb 28 13:44:03 HASS hass[5040]: , source=custom_components/light/tasm.py, message=Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/wstest/RESULT’, b’{“POWER”:“ON”}’, 0) at /srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/init.py:225, timestamp=1519843443.0840468, level=ERROR>
Feb 28 13:44:03 HASS hass[5040]: 2018-02-28 13:44:03 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 140277257080560: Received {‘type’: ‘call_service’, ‘service’: ‘turn_on’, ‘domain’: ‘homeassistant’, ‘id’: 24, ‘service_data’: {‘entity_id’: ‘light.wstestled’}}

here’s my YAML NOTE: I’m using folders for the light component

platform: tasm
name: “wstestled”
on_command_type: first
state_topic: “stat/wstest/POWER”
command_topic: “cmnd/wstest/POWER”
brightness_state_topic: “stat/wstest/RESULT”
brightness_command_topic: “cmnd/wstest/Dimmer”
brightness_value_template: “{{ value_json.Dimmer }}”
rgb_state_topic: “stat/wstest/RESULT”
rgb_command_topic: “cmnd/wstest/Color2”
rgb_value_template: “{{ value_json.Color }}”
effect_command_topic: “cmnd/wstest/Scheme”
effect_state_topic: “stat/wstest/RESULT”
effect_value_template: “{{ value_json.Scheme }}”
qos: 0
payload_on: “ON”
payload_off: “OFF”
optimistic: false

I have been using power instead of power1 but my Sonoff basic shows me 2 switches. As I have the power source for LEDs after Sonoff in the circuit, I use power1 to control the relay and power2 as far as I understand is used to control the connected LEDs via GPIO for on off commands. I’m not a developer, this is just kicking few things from the original component and few lines added.

I don’t see code responsible for RGBW, but RGB. Am I right?

Yes, I’ve cut everything I didn’t needed

@jtroberts
try changing your state_topic and add the state_value_template :

state_topic: "stat/wstest/RESULT"
state_value_template: "{{ value_json.POWER }}"

Does that help with the switch toggling back to OFF in HA ?

Hey there I’ve been trying to get your custom component to work, but when I check my configuration it says “Platform not found: light.tasm”. I’m running hass.io

I’ve never added a custom component before so it’s probably an issue caused by me. The tasm.py file is located in config/custom_components/light/tasm.py .

Any ideas?

Does this component support RGBW in one switch/entity?

Hi Guys,
this code here should do it for RGBW Lights. Color and White are working with Tasmota on a H801 and Wemos D1 Controller.

- platform: mqtt
  name: "LED Board 3"
  state_topic: "stat/LED_Board_3/RESULT"
  command_topic: "cmnd/LED_Board_3/POWER"
  state_value_template: "{{ value_json.POWER }}"
  brightness_state_topic: "stat/LED_Board_3/RESULT"
  brightness_command_topic: "cmnd/LED_Board_3/Dimmer"
  brightness_scale: 100
  brightness_value_template: "{{ value_json.Dimmer }}"
  white_value_state_topic: "stat/LED_Board_3/RESULT"
  white_value_command_topic: "cmnd/LED_Board_3/Channel4"
  white_value_scale: 100
  white_value_template: "{{ value_json.Channel[3] }}"
  rgb_state_topic: "stat/LED_Board_3/RESULT"
  rgb_command_topic: "cmnd/LED_Board_3/Color"
  rgb_command_template: "{{ '%02x%02x%02x' | format(red, green, blue)}}"
  rgb_value_template: "{{(value_json.Channel[0]*2.55)|int}},{{(value_json.Channel[1]*2.55)|int}},{{(value_json.Channel[2]*2.55)|int}}"
  effect_state_topic: "stat/LED_Board_3/RESULT"
  effect_command_topic: "cmnd/LED_Board_3/Scheme"
  effect_value_template: "{{ value_json.Scheme }}"
  effect_list:
    - 0
    - 1
    - 2
    - 3
    - 4
  payload_available: "Online"
  payload_not_available: "Offline"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  optimistic: false
  retain: true
1 Like

it works indeed!
just have loads of error messages:
Error parsing value: 'dict object' has no attribute 'Channel' (value: {"POWER":"on"}, template: {{(value_json.Channel[1]*2.55)|int}},{{(value_json.Channel[0]*2.55)|int}},{{(value_json.Channel[2]*2.55)|int}}

as tasmota sends this JSON and repeats RESULT once again only with power.
there could be check ‘if’ Channel present or something

Did anyone get a fix to these errors

Hello, i’m in the same boat here, using @ino 's code works fine (most of the time atleast) but i’m getting errors

Here’s a list of them:

Error parsing value: ‘dict object’ has no attribute ‘Channel’ (value: {“Scheme”:0}, template: {{(value_json.Channel[0]*2.55)|int}},{{(value_json.Channel[1]*2.55)|int}},{{(value_json.Channel[2]*2.55)|int}})

Exception in rgb_received when handling msg on ‘stat/ledstrip_outside/RESULT’: ‘{“Scheme”:0}’
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/mqtt/light/schema_basic.py”, line 315, in rgb_received
rgb = [int(val) for val in payload.split(‘,’)]
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/mqtt/light/schema_basic.py”, line 315, in
rgb = [int(val) for val in payload.split(‘,’)]
ValueError: invalid literal for int() with base 10: ‘{“Scheme”:0}’

Error parsing value: 'dict object' has no attribute 'Channel' (value: {"Scheme":0}, template: {{ value_json.Channel[3] }})

Exception in rgb_received when handling msg on ‘stat/ledstrip_outside/RESULT’: ‘{“POWER”:“ON”}’
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/mqtt/light/schema_basic.py”, line 315, in rgb_received
rgb = [int(val) for val in payload.split(‘,’)]
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/mqtt/light/schema_basic.py”, line 315, in
rgb = [int(val) for val in payload.split(‘,’)]
ValueError: invalid literal for int() with base 10: ‘{“POWER”:“ON”}’

And others that are the same but for different commands (eg. Off)

Hi,

first post here, hopefully I can format the code properly.

Seems that ‘dict Object’ -error occurs as when changing colour from HA it first sends e.g. Channel4 50 and then POWER ON. H801 responds to that like:

stat/saunaled/RESULT {"POWER":"ON","Dimmer":68,"Color":"4A4A4AAD00","HSBColor":"0,0,29","Channel":[29,29,29,67,0],"CT":153}

stat/saunaled/RESULT {"POWER":"ON"}

Value template is then trying to parse Channel[3] (meaning in this case value of 67) from the json but as it tries to parse latest response it does not find Channel from there.

This is my current setup here:

  - platform: mqtt
    name: "Saunaled"
    state_topic: "stat/saunaled/RESULT"
    command_topic: "cmnd/saunaled/POWER"
    state_value_template: "{{ value_json.POWER }}"
    brightness_state_topic: "stat/saunaled/RESULT"
    brightness_command_topic: "cmnd/saunaled/Dimmer"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    white_value_state_topic: "stat/saunaled/RESULT"
    white_value_command_topic: "cmnd/saunaled/Channel4"
    white_value_scale: 100
    white_value_template: >
      {% if value_json.Channel is defined %}
        {{ value_json.Channel[3] }}
      {% endif %}
    rgb_state_topic: "stat/saunaled/RESULT"
    rgb_command_topic: "cmnd/saunaled/Color"
    rgb_command_template: "{{ '%02x%02x%02x' | format(red, green, blue)}}"
    rgb_value_template: >
      {% if value_json.Channel is defined %}
        {{(value_json.Channel[0]*2.55)|int}},{{(value_json.Channel[1]*2.55)|int}},{{(value_json.Channel[2]*2.55)|int}}
     {% endif %}
    effect_state_topic: "stat/saunaled/RESULT"
    effect_command_topic: "cmnd/saunaled/Scheme"
    effect_value_template: "{{ value_json.Scheme }}"      
    effect_list:
      - 0
      - 1
      - 2
      - 3
      - 4
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    retain: true                                  

This seems to work “almost”. There is something weird going on when changing the brightness or the white value but I haven’t yet figured out what. Still, error message is now gone.

Or just flash it with ESPHome and have the issue resolved. :slight_smile:

I got this figured out for my H801 using Tasmota 6.5.0 using an RGBCWWW LED strip.

First you have to run this command in the Tasmota console: SetOption59 1

This will make so it always reports /tele/%topic%/STATE on state changes.

This contains all required values:

{
	"Time": "2019-05-26T22:01:10",
	"Uptime": "0T00:37:02",
	"Vcc": 3.105,
	"SleepMode": "Dynamic",
	"Sleep": 0,
	"LoadAvg": 159,
	"POWER": "ON",
	"Dimmer": 100,
	"Color": "00FF000000",
	"HSBColor": "120,100,100",
	"Channel": [0, 100, 0, 0, 0],
	"CT": 499,
	"Scheme": 0,
	"Fade": "OFF",
	"Speed": 1,
	"LedTable": "OFF",
	"Wifi": {
		"AP": 1,
		"SSId": "WiFi",
		"BSSId": "XX:XX:XX:XX:XX:XX",
		"Channel": 11,
		"RSSI": 70,
		"LinkCount": 1,
		"Downtime": "0T00:00:04"
	}
}

Which allow us to write a config containing both RGB and color temp controls, which are always showing correctly without errors in hass:

light:
  - platform: mqtt
    name: bookcase_light
    retain: true
    availability_topic: "tele/bookcase_light/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    state_topic: "tele/bookcase_light/STATE"
    state_value_template: "{{ value_json.POWER }}"
    command_topic: "cmnd/bookcase_light/POWER"
    brightness_state_topic: "tele/bookcase_light/STATE"
    brightness_command_topic: "cmnd/bookcase_light/DIMMER"
    brightness_scale: 100
    brightness_value_template: "{{ value_json.Dimmer }}"
    color_temp_command_topic: "cmnd/bookcase_light/CT"
    color_temp_state_topic: "tele/bookcase_light/STATE"
    color_temp_value_template: "{{ value_json.CT }}"
    rgb_state_topic: "tele/bookcase_light/STATE"
    rgb_command_topic: "cmnd/bookcase_light/Color"
    rgb_command_template: "{{ '%02x%02x%02x' | format(red, green, blue)}}"
    rgb_value_template: "{{(value_json.Channel[0]*2.55)|int}},{{(value_json.Channel[1]*2.55)|int}},{{(value_json.Channel[2]*2.55)|int}}"
    optimistic: false
1 Like

This is great News. THX so much!:+1::ok_hand: