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