Light switches through 1/0 instead ON/OFF

I’ve got an Tasmotta ZigBee bridge and I connected an tuya dimmer on it… since a view days that the device is supported with the latest tasmota

After it got paired. I can control the device. (Trough Tasmota console/HA still thinks its a router)
When I turn on an off the device the console gives me a status 1 for on and 0 for off.

I managed to get it controlled trough HA…
HA cannot see if the device is on or off because of the 1 and 1 status.

The setting

    state_on: "1"
    state_off: "0"

is not allowed
How to get around this?

- platform: mqtt
    name: "Dimmer Keuken"
    state_topic: "tele/tasmota_ZigBee/SENSOR"
    command_topic: "cmnd/tasmota_ZigBee/ZbSend"
    brightness_state_topic: "tele/tasmota_ZigBee/SENSOR"
    brightness_command_topic: "cmnd/tasmota_ZigBee/ZbSend"
    state_value_template: "{{ value_json.Power }}"
    brightness_value_template: "{{ value_json.TuyaTempTarget }}"
    payload_on: '{"Device":"0x4D1A","Write":{"Power":1}}'
    payload_off: '{"Device":"0x4D1A","Write":{"Power":0}}'
    on_command_type: "first"
#    state_on: "1"
#    state_off: "0
    qos: 0

for now I placed

    retain: true
    optimistic: true

it is possible that the brightness is not working right now. For now HA will start the lights only doesnt change the status.

edit: I see that the brightness isn’t also working.
it sends an number trough MQTT instead of this command:
{"Device":"0x4D1A","Write":{"Dimmer":550}}

try the following for the state template:

state_value_template: >
  {% if value_json.Power | int == 1 %}
    'on'
  {% elif value_json.Power | int == 0 %}
    'off'
  {% endif %}

I don’t know how the dimmer works but you can probably use the above as an example to get the brightness template working too.

Thanks for the response.

I tried it without luck.

When I pushed the button or try to turn on the light I get this MQTT message:

tele/tasmota_ZigBee/SENSOR {"ZbReceived":{"0x4D1A":{"Device":"0x4D1A","Power":1,"Endpoint":1,"LinkQuality":0}}}

The topic listener:

{
    "ZbReceived": {
        "0x4D1A": {
            "Device": "0x4D1A",
            "Power": 1,
            "Endpoint": 1,
            "LinkQuality": 37
        }
    }

This is my light config:

  - platform: mqtt
    name: "Dimmer Keuken"
    state_topic: "tele/tasmota_ZigBee/SENSOR"
    state_value_template: >
      {% if "value_json.0x4D1A.Power" | int == 1 %}
        'on'
      {% elif "value_json.0x4D1A.Power" | int == 0 %}
        'off'
      {% endif %}
    command_topic: "cmnd/tasmota_ZigBee/ZbSend"
    brightness_state_topic: "tele/tasmota_ZigBee/SENSOR"
    brightness_command_topic: "cmnd/tasmota_ZigBee/ZbSend"
    brightness_value_template: "{{ value_json.TuyaTempTarget }}"
    payload_on: '{"Device":"0x4D1A","Write":{"Power":1}}'
    payload_off: '{"Device":"0x4D1A","Write":{"Power":0}}'
    on_command_type: "first"
    qos: 0

What is the command topic payload? If you turn on/off the light directly from Tasmota outside of HA what is the payload of the command topic and the payload of the resulting state topic?

And FYI, unless you quote my username (using @finity) or click the reply button in my post I don’t get notified that you replied to me. So I won’t see it until I start going thru my unread messages.

Hi @finity ,

thanks for the reply.

On the console in Tasmota I use the following commands:
To tun on:

ZbSend {"Device":"0x4D1A","Write":{"Power":1}}

To tun off:

ZbSend {"Device":"0x4D1A","Write":{"Power":0}}

For the dimmer it is:

ZbSend {"Device":"0x4D1A","Write":{"Dimmer":600}}

(The value between 0 to1000)

In HA trough the MQTT Publish a packet

cmnd/tasmota_ZigBee/ZbSend
{"Device":"0x4D1A","Write":{"Power":1}} 

Command to turn of the device

cmnd/tasmota_ZigBee/ZbSend
{"Device":"0x4D1A","Write":{"Power":0}} 

Command to dimm the light

cmnd/tasmota_ZigBee/ZbSend
{"Device":"0x4D1A","Write":{"Dimmer":550}}

Result in consol tasmota when Turning on light:

19:20:55.753 MQT: stat/tasmota_ZigBee/RESULT = {"ZbSend":"Done"}
19:20:55.843 MQT: tele/tasmota_ZigBee/SENSOR = {"ZbReceived":{"0x4D1A":{"Device":"0x4D1A","Power":1,"Endpoint":1,"LinkQuality":18}}}

Result in consol tasmota when Turning off light:

19:24:20.241 MQT: stat/tasmota_ZigBee/RESULT = {"ZbSend":"Done"}
19:24:20.329 MQT: tele/tasmota_ZigBee/SENSOR = {"ZbReceived":{"0x4D1A":{"Device":"0x4D1A","Power":0,"Endpoint":1,"LinkQuality":10}}}

Result in consol tasmota when Turning Dimm light:

19:25:31.140 MQT: stat/tasmota_ZigBee/RESULT = {"ZbSend":"Done"}
19:25:31.230 MQT: tele/tasmota_ZigBee/SENSOR = {"ZbReceived":{"0x4D1A":{"Device":"0x4D1A","TuyaTempTarget":85,"Endpoint":1,"LinkQuality":18}}}

I’m trying to work this all out but I’m stuck on trying to change the command topic between the power on/off and the brightness.

what happens if you publish this to the command topic (cmnd/tasmota_ZigBee/ZbSend):

{"Device":"0x4D1A","Write":{"Power":1, "Dimmer":1000}}

I hope the bulb turns on at full brightness.

And then this command:

{"Device":"0x4D1A","Write":{"Power":0, "Dimmer":0}}

hopefully turns the bulb off.

And this command:

{"Device":"0x4D1A","Write":{"Power":1, "Dimmer":500}}

hopefully turns the bulb on to 50% brightness.

Could you try those and let me know the results along with the returned values on the tele topic (tele/tasmota_ZigBee/SENSOR) for all three of those commands.

Hi @finity

{"Device":"0x4D1A","Write":{"Power":1, "Dimmer":1000}}

MQT: stat/tasmota_ZigBee/RESULT = {"ZbSend":"Done"}
MQT: tele/tasmota_ZigBee/SENSOR = {"ZbReceived":{"0x4D1A":{"Device":"0x4D1A","Power":1,"Endpoint":1,"LinkQuality":0}}}
MQT: tele/tasmota_ZigBee/SENSOR = {"ZbReceived":{"0x4D1A":{"Device":"0x4D1A","Power":1,"Endpoint":1,"LinkQuality":0}}}

Turns it on but nog changing the Dimmer state ( picks the last last state befor turning off.

{"Device":"0x4D1A","Write":{"Power":0, "Dimmer":0}}

MQT: stat/tasmota_ZigBee/RESULT = {"ZbSend":"Done"}
MQT: tele/tasmota_ZigBee/SENSOR = {"ZbReceived":{"0x4D1A":{"Device":"0x4D1A","Power":0,"Endpoint":1,"LinkQuality":0}}}
MQT: stat/tasmota_ZigBee/RESULT = {"ZbData":"ZbData 0x4D1A,0680859D6000FF0E05010F0064000080FFFFFF000820040E010100"}

Dimmer goes off

{"Device":"0x4D1A","Write":{"Power":1, "Dimmer":500}}

stat/tasmota_ZigBee/RESULT = {"ZbSend":"Done"}
tele/tasmota_ZigBee/SENSOR = {"ZbReceived":{"0x4D1A":{"Device":"0x4D1A","Power":1,"Endpoint":1,"LinkQuality":0}}}
ZIG: Auto-responder: ZbSend {"Device":"0x4D1A","Cluster":"0x000A","Endpoint":1,"Response":"000A/0007":674255266}
tele/tasmota_ZigBee/SENSOR = {"ZbReceived":{"0x4D1A":{"Device":"0x4D1A","Cluster":10,"Read":[7],"ReadNames":{"LocalTime":true},"Endpoint":1,"LinkQuality":3}}}

Same outcome as with dimmer 1000 in command

well, I can get you started with the on/off but I’m not sure how to handle the dimming.

maybe you can get more inspiration from my nudge and figure out the brightness from there.

here is what I have so far:

- platform: mqtt
    name: "Dimmer Keuken"
    #schema: template
    command_topic: "cmnd/tasmota_ZigBee/ZbSend"
    brightness_command_topic: "cmnd/tasmota_ZigBee/ZbSend"
    state_topic: "tele/tasmota_ZigBee/SENSOR"
    brightness_state_topic: "tele/tasmota_ZigBee/SENSOR"
    state_value_template: >
      {% if value_json.ZbReceived['0x4D1A'].Device == "0x4D1A" and value_json.ZbReceived['0x4D1A'].Power == 1 %}
        {"Device":"0x4D1A","Write":{"Power":1}}
      {% elif value_json.ZbReceived['0x4D1A'].Device == "0x4D1A" and value_json.ZbReceived['0x4D1A'].Power == 0 %}
        {"Device":"0x4D1A","Write":{"Power":0}}
      {% endif %}
    brightness_value_template: >
      {{ value_json.TuyaTempTarget }} ##<--- this doesn't work for brightness as is
    brightness_scale: 1000
    payload_on: '{"Device":"0x4D1A","Write":{"Power":1}}'
    payload_off: '{"Device":"0x4D1A","Write":{"Power":0}}'
    on_command_type: "first"
    qos: 0

But you might also be better off going to the tasmota forum and asking there since this doesn’t seem to correlate to any of the standard light control schemas in HA.

Wow @finity greate!
thanks or your time!
It works!

Only the dimmer function.
I will look that I make an post at tasmota

Hi @Marcmk

Any luck with the dimmer config?

Its little bit on hold right now
Busy with my new doorbel integration.
After that I will pick it up and look in the tasmota forums or perhaps create one there.
If I find somthing I will post it, if someone is not faster than me :slight_smile:

1 Like

I have been able to control brightness (Dimmer) and color_temp (CT) using light.mqtt template schema as per below:

Note I have SetOption89, SetOption 100 and SetOption 112 enabled, if you dont, the command template could need adjusting a little

  - platform: "mqtt"
    unique_id: zigbee_light
    name: "Zigbee Light"
    schema: template
    state_topic: "tele/tasmota/DeviceName/SENSOR"
    command_topic: "cmnd/tasmota_zigbee/DeviceName/SENSOR/ZbSend"
    command_on_template: >
      {%- if brightness is defined -%}
      {"Device":"DeviceName","send":{"Dimmer": {{ brightness }}}}
      {%- endif -%}
      {%- if color_temp is defined -%}
      {"Device":"DeviceName","send":{"CT": {{ color_temp }}}}
      {%- endif -%}
      {%- if state is defined -%}
      {"Device":"DeviceName","send":{"Power": {{ state }}}}
      {%- endif -%}
    command_off_template: '{"Device":"DeviceName","send":{"Power": {{ state }}}}'
    state_template: '{{ value_json.state }}'
    brightness_template: '{{ value_json.brightness }}'
    color_temp_template: '{{ value.json.color_temp }}'
    qos: 0
    optimistic: true

hope its helpful for someone.

light.mqtt template schema documentation here: MQTT Light - Home Assistant

unfortunately the template schema only supports rgb color mode and not hs or xy which tasmota supports. I’ve made a feature request here, but cant see it getting may upvotes!

@asifkassam
Your config is not working for my device.
The lights are switched trough Write instead of send.

: /

Correct me If i’m wrong but I don’t see any dimmer (brightness) function

mine is just a zigbee lightbulb with no dimmer switch. dimmer is part of the Tasmota Zigbee ZBSend command set for lights: Zigbee - Tasmota.

I am unsure about the write command, i have always used send

@asifkassam
I use nearly the same config as you do:

- platform: mqtt
  name: "Zigbee Bulb 1"
  availability: 
    topic: "home/tele/tasmota_zigbee_706475/LWT"
    payload_available: "Online"
    payload_not_available: "offline"
  schema: template
  command_topic: 'home/cmnd/tasmota_zigbee_706475/ZbSend'

  #command_on_template: '{"Device":"0x9694", "Send":{"power":1}}'
  command_on_template: >
    
     {"Device":"0x9694", "Send":{
      
      {%- if brightness is defined -%}
        "Dimmer": {{ brightness }}
      {%- endif -%}
      
      {%- if brightness is not defined and red is not defined and blue is not defined and green is not defined -%}
        "power": 1
      {%- endif -%}
      
      {%- if red is defined and green is defined and blue is defined -%}
        "hue": {{red}}
      {%- endif -%}
      
     }}

  command_off_template: '{"Device":"0x9694", "Send":{"power":0}}'
  brightness_template: '{{ value_json.brightness }}'
  red_template: '{{ value_json.color[0] }}'
  green_template: '{{ value_json.color[1] }}'
  blue_template: '{{ value_json.color[2] }}'

In addition i messing around with colors. Due to the fact the schema:template does not use hue i’m unable to set correct colors.

Does anybody know how to do that or convert colors in that schema?

I ended up using the default template and using MQTT demultiplexers with automations to create the various state and command topics as individual topics, then my yaml looked like below:

you could adopt this approach for hs, i used the xy values from tasmota (although it needed some mapping in the automation demultiplexer and command topic. (see MQTT demultiplexer automatic sensor discovery for tasmota2zigbee for examples of how to do create new topics and automations)

#Aurora AOne Zigbee Light 1
  - platform: "mqtt"
    unique_id: zigbee_aone_light_default
    name: "Aurora AOne"
    on_command_type: first
    availability: 
      topic: "sensor/AOne/availability"
      payload_available: True
      payload_not_available: False
    state_topic: "sensor/AOne/power"
    state_value_template: '{{ value_json["AOne"]["Power"] }}'
    payload_on: 1
    payload_off: 0
    command_topic: "cmnd/AOne/power"
    brightness_scale: 254
    brightness_state_topic: "sensor/AOne/brightness"
    brightness_value_template: '{{ value_json["AOne"]["Dimmer"] }}'
    brightness_command_topic: "cmnd/AOne/brightness"
    xy_state_topic: "sensor/AOne/xy"
    xy_value_template: '{{ value_json["AOne"]["XY"] }}'
    xy_command_topic: "cmnd/AOne/xy"
    color_temp_state_topic: "sensor/AOne/colortemp"
    color_temp_value_template: '{{ value_json["AOne"]["CT"] }}'
    color_temp_command_topic: "cmnd/AOne/colortemp"
    max_mireds: 370
    min_mireds: 153
    qos: 0
    optimistic: false
    retain: false
    json_attributes_topic: "tele/tasmota/AOne/SENSOR"
    json_attributes_template: "{{ value_json.AOne | tojson }}"

Note i opted to use device friendly names my topics

1 Like