Sonoff B1 LED Wifi Bulb template error in log

Hi,

I have received my bub and I have installed the Tasmota firmware from: https://github.com/arendst/Sonoff-Tasmota/wiki

I have it working in HA, just getting an error in the logs that I would like to resolve.

All the examples I have found suggest that this should work correctly, so I’m not sure if it’s something I have wrong or an issue/not yet supported feature.

When the light is switched on, I see the following MQTT commands which are corret:

cmnd/sonoffb1/POWER ON
stat/sonoffb1/RESULT {"POWER":"ON"}
stat/sonoffb1/POWER ON

I get the following error in the HA log.

 Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
    self._callback(*self._args)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 232, in async_mqtt_topic_subscriber
    hass.async_run_job(msg_callback, dp_topic, payload, dp_qos)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 247, in async_run_job
    target(*args)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/mqtt.py", line 233, in brightness_received
    device_value = float(templates[CONF_BRIGHTNESS](payload))
ValueError: could not convert string to float:

My config:

light:  
  - platform: mqtt
    name: "Lounge lamp"
    command_topic: "cmnd/sonoffb1/POWER"
    state_topic: "stat/sonoffb1/POWER"
#    state_value_template: "{{ value_json.state }}"
    rgb_command_topic: "cmnd/sonoffb1/COLOR"
    rgb_command_template: "{{ '#%02x%02x%02x0000'| format(blue, green, red) }}"
#    rgb_state_topic: "stat/sonoffb1/COLOR/RESULT"
    brightness_state_topic: "stat/sonoffb1/RESULT"
    brightness_value_template: "{{ value_json.Dimmer }}"
    brightness_command_topic: "cmnd/sonoffb1/DIMMER"
    brightness_scale: 100
    color_temp_command_topic: "cmnd/sonoffb1/CT"
#    color_temp_state_topic: "stat/sonoffb1/RESULT"
#    color_temp_value_template: "{{ value_json.CT }}"
    qos: 0
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    retain: true

The issues is related to the following config, if I remove the lines I get no errors, but the brightness state is not maintained in the GUI.

brightness_state_topic: "stat/sonoffb1/RESULT"
brightness_value_template: "{{ value_json.Dimmer }}"

There is no Dimmer value present in the topic when it first turns on: stat/sonoffb1/RESULT so it shouldn’t be matching anything, why the error???

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

Thanks for any light you can shed on the issue!

Anyone able to shed some light on error I get?

 Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
    self._callback(*self._args)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 232, in async_mqtt_topic_subscriber
    hass.async_run_job(msg_callback, dp_topic, payload, dp_qos)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 247, in async_run_job
    target(*args)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/light/mqtt.py", line 233, in brightness_received
    device_value = float(templates[CONF_BRIGHTNESS](payload))
ValueError: could not convert string to float:`Preformatted text`

So it seems that it’s unhappy that the value_json.Dimmer does not exist, and it’s trying to process the error as a int.

Is there a way to do something like: {if defined value_json.Dimmer {{value_json.Dimmer}}}

brightness_value_template: “{{ value_json.brightness }}”

Did you get this working mate?

I’d be interested to see if this works as well, I noticed this in my logs as well with the AiLight firwmare, although the bulb works fine.

These guys have it worked out. See bottom config
No errors now!

Thanks for the update, looks like I have it working but it’s missing the 4th channel for me as I have a RGBW bulb. I’ll see if I can adapt things.

So I have found a few issues with the current templates and retained messages making the B1 come on when reconnecting to the MQTT server I worked out this is best approach:

On the sonoff B1 its best to turn on PoweRetain so Homassistant can see the status when it first starts up, also SetOption 4 on so that the responses are the same as the commands, set the following options:

PowerRetain on
SetOption4 on
Fade on (optional, but makes the transitions slower)
Speed 5 (optional, but makes the transitions slower)

light:  
  - platform: mqtt
    name: "Lounge lamp"
    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 }}"
    effect_list:
      - 0
      - 1
      - 2
      - 3
      - 4
    availability_topic: "tele/sonoffb1/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 0
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    retain: false