Sonoff Mini to only send MQTT and not actually cut power?

Hi all,

I recently installed a Sonoff Mini thinking it was the solution for wanting a physical switch to control my existing yeelight smart bulb setup. However I’m now experiencing the situation where the Sonoff will cut power to the bulb rendering it unavailable.

Ideally I would like to retain colour/voice control etc for the bulb and be able to use the physical switch in my wall when desired. Is there a way to configure the Sonoff Mini to only send On/Off signals to the bulb when the physical switch is toggled and have the actual power cut be limited to a specific command through HA?

If the Sonoff Mini was infact the wrong way to go about this could anybody recommend a better route?

Thanks in advance :slight_smile:

1 Like

You can flash them with Tasmota and assign an MQTT topic for single, double an hold actions.

I have flashed it with Tasmota and have the MQTT settings according to the Drzzs video. Everything works in terms of toggling the switch power, either through HA or the physical switch. The problem remains however that when the on/off is actioned by the Sonoff it makes the Yeelight bulb become unavailable.

Unfortunately I don’t fully understand

My config currently looks like this:

  - platform: mqtt
    name: "Jonathan Top Light"
    command_topic: "cmnd/sonoffJonathan/power"
    state_topic: "stat/sonoffJonathan/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

I have GPIO4 set to Switch1

Go to your Tasmota web console and type SwitchMode1 5, then SetOption32 10. Now create this two rules in the console:

  1. This rule send a toggle message to topic “cmnd/LohaLed1/power” with a single press and send a toogle message to the topic “cmnd/kitchen_leds/power” when the button is press and hold.

    rule1 on switch1#state=2 do publish cmnd/LohaLed1/power toggle endon on switch1#state=3 do publish cmnd/kitchen_leds/power toggle endon

    rule1 1

  2. I use this rule to disable the rule 1 and use switch as normal in case the wifi or the Mqtt connection is lost.

    rule2 on Mqtt#Disconnected do rule1 0 endon on Mqtt#Connected do rule1 1 endon

    rule2 1

Change the topics to your needs. If your yeelight bulb doesn’t have Mqtt you need to create an automation to toggle your lights when message is received on those topics.

Check this video with a better explanation:

1 Like

Is this the best way to achieve a always-on smart light system in your opinion?

With Tasmota on the Mini and connected to MQTT broker on Home Assistant, go to the Tasmota console. There are only three commands needed:

PowerOnState 1
SwitchMode1 0
SetOption114 1

PowerOnState 1 turns the relay on upon start. SeitchMode1 0 reports a TOGGLE whenever the Mini switch detects a change (on-to-off or off-to-on) on MQTT for your Mini topic (will use this later). And the real magic is SetOption114 1 which disconnects the switch from the relay. Toggling the switch now physically does nothing to the relay.

Now you need an Automation in HA. Create one with the following Trigger and Condition setup:

Mode: Single
Trigger type: MQTT
Topic: stat/<Your Mini R2 MQTT Name>/RESULT
Condition type: Template
Value template: {{ trigger.payload_json['Switch1']['Action'] == 'TOGGLE' }}
Action type: Device
Device: <your light>
Action: Toggle <your light>

With these settings when there is power loss and the lights were off, they will turn on when electricity is back. Of course it can be solved with HA with automations but the lights will be on for around 2-3 minutes until HA starts and automation is executed. I wonder if it is possible to create a rule in Tasmota which will power on the relay on boot (so PowerOnState 1 as it is) then detached should be switched off somehow and after HA boots up previous state should be recovered (on or off).

This would be far easier with esphome. Just follow the guide.

Then comment out the relay parts and it will stay on.
But far easier just to wire the mains input to the mini and the bulb and ignore the output from the relay.

1 Like

Just what I was thinking - it can be that complicated :point_down:

or as simple as having everything neatly in one place without any automations or cli usage :point_down:

  - platform: gpio
    pin: GPIO12
    restore_mode: ALWAYS_ON

  - platform: gpio
    pin: GPIO04
    name: TOGGLE
        - homeassistant.service:
            service: light.toggle
              entity_id: light.your_light
1 Like

But this solution has weak point - when HA is down for some reason you will loose possibility to control the lights. With the rule “when mqtt or wifi is disconnected then attach relay to switch” you can still control the lights old fashioned way.

But you could still use the app for the bulb.

Thanks a lot for helping me. I switched to ESPHome from Tasmota.
Here is my yaml:

  device_name: sonoffmini_1
  device_ip: 192.168.x.x

  name: ${device_name}
  friendly_name: Łazienka Góra Włącznik Światła
  platform: ESP8266
  board: esp8285

  ssid: !secret wifi_ssid
  password: !secret wifi_password
    static_ip: ${device_ip}
    gateway: 192.168.x.x
  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Lazienka-Gora-Wlacznik-Swiatla"
    password: "xxx"

  reboot_timeout: 15min
    key: "xxx"
  password: "xxx"

# the web_server & sensor components can be removed without affecting core functionaility.

  port: 80

  - platform: wifi_signal
    name: Wifi
    update_interval: 60s
  - platform: uptime
    name: Czas włączenia

# Device specific Config Begins Below #

  - platform: gpio
    pin: GPIO00
    id: reset
    internal: true
      - invert:
      - delayed_off: 10ms
      - switch.toggle:
          id: relay_1

  - platform: gpio
    name: Włącznik
    icon: "mdi:lightbulb"
    pin: GPIO04
    id: switch_1
        - homeassistant.service:
            service: light.toggle
              entity_id: light.lazienka_gora

  - platform: gpio
    name: Zasilanie
    icon: "mdi:power"
    pin: GPIO12
    id: relay_1
    restore_mode: ALWAYS_ON

  - platform: restart
    name: "Restart"
    number: GPIO13
    inverted: true

  - platform: esp8266_pwm
    id: blue_led
    pin: GPIO13
    inverted: True

  # the 4 lines below define the Blue LED light on Sonoff Mini, to expose in HomeAssistant remove line "internal: true"
  - platform: monochromatic
    name: ${device_name}_blueled
    output: blue_led
    internal: true # hides the Blue LED from HomeAssistant

I have Wiz bulbs which have memory after power but for some reason it doesn’t work (lights turn on after power cut off). I suppose I should run some “on_boot” commands but I have no idea how to start…

you need to read this stuff about “restore from flash”

Don’t forget it’s esphome here and you have full control and ownership to do all the things that you want, like checking for api and/or wifi connection and fire commands differently :point_down:

1 Like