Sonoff B1 with tasmota

Sonoff B1 flashed with tasmota 5.9.1 firmware.

Config in home assistant (is working) but get error message in log’s

light 5:

  • platform: mqtt
    name: “Lounge lamp”
    command_topic: “cmnd/sonoffb1/POWER”
    state_topic: “stat/sonoffb1/POWER”
    rgb_command_topic: “cmnd/sonoffb1/COLOR”
    rgb_command_template: “{{ ‘#%02x%02x%02x0000’| format(blue, green, red) }}”
    brightness_state_topic: “stat/sonoffb1/RESULT”
    brightness_value_template: “{{ value_json.brightness }}”
    brightness_command_topic: “cmnd/sonoffb1/DIMMER”
    brightness_scale: 100
    color_temp_command_topic: “cmnd/sonoffb1/CT”
    qos: 0
    payload_on: “ON”
    payload_off: “OFF”
    optimistic: false
    retain: true

Error doing job: Exception in callback async_subscribe..async_mqtt_topic_subscriber(‘stat/sonoffb1/RESULT’, b’{“POWER”:“OFF”}’, 0) at /srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/mqtt/
Traceback (most recent call last):
File “/usr/lib/python3.5/asyncio/”, line 126, in _run
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/mqtt/”, line 232, in async_mqtt_topic_subscriber
hass.async_run_job(msg_callback, dp_topic, payload, dp_qos)
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/”, line 253, in async_run_job
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/light/”, line 241, in brightness_received
device_value = float(templatesCONF_BRIGHTNESS)
ValueError: could not convert string to float:


hi looking for some help. I put your configuration as a switch and it works without errors, but i think it needs to go as a light so i can change colors, brigntness. When I put it under light i get errors.
Any guidance?
thank you

Hi Juan,

Due to the lack off support I already abended Sonoff B1 with home assistant.

Best Regards

HI, ok, this now works with no trouble. only issue is the colour palette is inverted. need more playing with it, but works

  • platform: mqtt
    name: “Living Lamp Bulb”
    state_topic: “stat/sonoffB1_01/livingbulb/POWER”
    command_topic: “cmnd/sonoffB1_01/livingbulb/power”
    brightness_state_topic: “stat/sonoffB1_01/livingbulb/RESULT”
    brightness_command_topic: “cmnd/sonoffB1_01/livingbulb/DIMMER”
    brightness_value_template: “{{ value_json.brightness }}”
    brightness_scale: 100
    rgb_state_topic: “stat/sonoffB1_01/livingbulb/RESULT”
    rgb_command_topic: “cmnd/sonoffB1_01/livingbulb/COLOR”
    rgb_command_template: “{{ ‘#%02x%02x%02x0000’| format(blue, green, red) }}”
    rgb_value_template: “{{ value_json.rgb | join(’,’) }}”
    color_temp_command_topic: “cmnd/sonoffB1_01/livingbulb/CT”
    qos: 0
    payload_on: “ON”
    payload_off: “OFF”
    optimistic: false
1 Like

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

1 Like

thank you for your help

1 Like

I’ve added some extra options so more functions of the lamp can be utilized with hass. I followed the commands over at Github.

Firstly you can change some settings of the lamp like enabling a fade using the mqtt command cmnd/YOUR_SONOFF_LAMP/Fade on,
correct some light intensity with cmnd/YOUR_SONOFF_LAMP/Ledtable on,
change the fading speed with cmnd/YOUR_SONOFF_LAMP/Speed number (for a number 1 to 20, 1=fast),
and change the wakeup duration with you guessed it cmnd/YOUR_SONOFF_LAMP/Wakeupduration seconds (for the number of seconds you want. I’ve set mine to 120, so two minutes).
You can btw set these from within home assistant using the service mqtt.publish and as data {"topic":"cmnd/YOUR_SONOFF_LAMP/Fade", "payload":"on"} for example.

Next there are some Schemes built into Tasmota and I made an input_select and automation for that:
(in configuration.yaml)

    name: 'Select Scheme'
      - Default
      - Cycle Colours Clockwise
      - Cycle Colours Counter Clockwise
      - Random Colours

(in automations.yaml)

  alias: Set Bedroom Lamp Scheme
  - platform: state
    entity_id: input_select.bedroom_lamp_scheme
  - service: mqtt.publish
      topic: "cmnd/sonoff3/scheme"
      payload: '{% if states.input_select.bedroom_lamp_scheme.state == "Default" %}0{% elif states.input_select.bedroom_lamp_scheme.state == "Cycle Colours Clockwise" %}2{% elif states.input_select.bedroom_lamp_scheme.state == "Cycle Colours Counter Clockwise" %}3{% elif states.input_select.bedroom_lamp_scheme.state == "Random Colours" %}4{% endif %}'

Besides this scheme control I also added a wake-up button:
(in scripts.yaml)

  alias: Bedroom Lamp Wake-up
  - data:
      payload: '100'
      topic: cmnd/sonoff3/wakeup
    service: mqtt.publish

Finally I put all these things together in a group to make it clear they belong to the same lamp:
(in groups.yaml)

Bedroom Lamp:
  name: Bedroom Lamp
  control: hidden
    - light.bedroom_lamp
    - input_select.bedroom_lamp_scheme
    - script.bedroom_lamp_wakeup



Hi, thanks so much for all your work. I’m really new to all this. The new is so cool, but I have limited programming experience. I use the interface to create automations. I do have the B1 bulbs flashed with tasmota and able to change all the features from the dashboard including the 4 schemes. My question is, can you help show me what information I put into the action area to make the bulb run one of the schemes? For instance, I have an alarm clock that I can set the time to trigger the bulb at a certain time. I have it turning on and off the bulb with Call Servie, light.turn_on and the service data {“entity_id”: “light.b1”}. How exactly would I tell it to run the number 3 scheme? Or turn on and turn them all red? Remember I’m using the automation interface in hassio so it has a drop down menu for Action Type, Service, and Service Data. If I could see an example, that would be awesome. I’m trying to get my hallway B1 lights (4 of them) to turn on at the alarm clock time and run some cool colors…mainly for the kids when they go to bed and wake up. What nerds we are, well I’ll speak for myself. I guess the other issue is how does the wife turn it back to the normal off-white color when I want them to look normal “so to speak” so she doesn’t start hassling me over the colored hall way when family is over…hahaha. Thanks for any feedback whoever is out there.

Do it the old fashioned way, the configuration in the front end is a pain to use and ironically more complicated.

Doing it properly means you can cut and paste code from the docs and what other people have shared.

Hi, the old fashion way would work for me too, you’re right I might understand it better and the copy and paste is much easier. Still can’t find any example of how to tell the B1 bulb to run a scheme or a fade and then revert back to the normal white color…uh…say…after a delay. If you run across anything, please share. Thanks for response

If you set up scenes for how you want the bulbs to be at each state, eg and scene.normal you can simply this as the action for a five minute delay…

    - service: scene.turn_on
    - delay: '00:05:00'
    - service: scene.turn_on
      entity_id: scene.normal

Below is what I copied from someone and got it work on the dashboard, etc.
By the way, thanks for you help! How would I tell it to run the effects 3?


  • platform: mqtt
    name: “B1”
    command_topic: “cmnd/B1/power”
    state_topic: “stat/B1/POWER”
    rgb_state_topic: “stat/B1/color”
    rgb_command_topic: “cmnd/B1/color”
    brightness_state_topic: “stat/B1/dimmer”
    brightness_command_topic: “cmnd/B1/dimmer”
    color_temp_state_topic: “stat/B1/CT”
    color_temp_command_topic: “cmnd/B1/CT”
    effect_command_topic: “cmnd/B1/SCHEME”
    effect_state_topic: “stat/B1/SCHEME”
    rgb_command_template: “{{ ‘#%02x%02x%02x0000’| format(red, green, blue) }}”
    rgb_value_template: “{{ ‘#%02x%02x%02x0000’| format(red, green, blue) }}”
    color_temp_value_template: “{{ value_json.CT }}”
    brightness_scale: 100
    on_command_type: “first”
    - 0
    - 1
    - 2
    - 3
    - 4
    qos: 0
    payload_on: “ON”
    payload_off: “OFF”
    payload_available: “Online”
    payload_not_available: “Offline”
    retain: false

Hi guys, did you have to reflash the lightbulb with other firmware? If so, where can I get the firmware and how do I flash the bulb? I’m thinking of getting one of the following as an experiment for my home assistant / amazon echo:

Its just an awful lot of money to spend for something that will not work.

Thank you. Works like a charm!!

1 Like

How do you establish the colour (color) of the bulb within the automation?

hi guys, i trying to achieve color in an automation, between 7PM and 7AM i want to be able to use the Sonoff b1 as a night light. during the day i want to use it as a normal white light. trigger is a binary door sensor.


- platform: mqtt
    name: "b1"
    state_topic: "stat/sonoffb1/POWER"
    state_value_template: "{{ value }}"
    command_topic: "cmnd/sonoffb1/POWER"
    brightness_state_topic: "stat/sonoffb1/DIMMER"
    brightness_command_topic: "cmnd/sonoffb1/Dimmer"
    brightness_value_template: "{{ value_json.Dimmer }}"
    brightness_scale: 100
    rgb_state_topic: "stat/sonoffb1/COLOR"
    rgb_command_topic: "cmnd/sonoffb1/Color"
    rgb_command_template: "{{ '%02x%02x%02x0000' | format(red, green, blue) }}"
    rgb_value_template: "{{ value_json.Color[0:2]|int(base=16) }},{{ value_json.Color[2:4]|int(base=16) }},{{ value_json.Color[4:6]|int(base=16) }}"
    color_temp_state_topic: "stat/sonoffb1/CT"
    color_temp_command_topic: "cmnd/sonoffb1/CT"
    color_temp_value_template: "{{ value_json.CT }}"
    effect_state_topic: "stat/sonoffb1/SCHEME"
    effect_command_topic: "cmnd/sonoffb1/Scheme"
    effect_value_template: "{{ value_json.Scheme }}"
      - 0
      - 1
      - 2
      - 3
      - 4
    availability_topic: "tele/sonoffb1/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    retain: true


      alias: Hallway Sensor
      - entity_id: binary_sensor.hallway_door
        from: 'off'
        platform: state
        to: 'on'
      - after: '19:00'
        before: '7:00'
        condition: time
      - data:
          entity_id: light.b1
            dimmer: 100
            color: FF00000000
        service: light.turn_on

Hope someone can help, i am novice at this and coding is not my strong point. Thank you.

Are you using the automation editor in the UI to put it together? It looks like you might have an issue with your conditions.

You might try this:

  - condition: time
    before: 07:00:00
  - condition: time
    after: 19:00:00

To troubleshoot your actions, you can use the dev_service tab to call a service with the data you’ve got listed, iron out any issues with the service call, then weave it back into your automation.

Hi, yes i used the UI to put it togeather. My condition seems to work fine, with the trigger and actions. My only problem is color. I cant seem to change the color using automation. I can change color using the HA, UI and via the tasmota console. Thanks.

You may need to make two service calls. First, turn the light on, second, set the colour. Some of my lights do not support changing the colour value while the light is off.