Automation toggle not possible with hard switch | Shelly 1

I have simple scenario: a Shelly 1 and a Motion sensor in the bathroom are supposed to accept the physical switch attached to the Shelly 1 as a toggle for the automation itself.

Meaning if I swith the lights to OFF, a movement in the bathroom is not supposed to trigger the lights to go on. For this purpose I set the Shelly to the following setting on its web interface “Toggle Switch - Set Shelly device to be “Toggle” switch. Act as a flip switch with one state for “ON” and one state for “OFF”.”

In my understanding I would have to set the automation to say that the Shelly is supposed to react to the automation if it is set to “ON”. What happens though is that this is causing an endless circle, where the fact that the lights are on are causing the lights to stay on- instead of listening to the OFF automation which is set for 2 minutes.

It seems that Home Assistant does not seem to discriminate between the state of the device output and the device setting (the hard switch attached outside the wall). Shelly understands this difference however, the automation UI does not offer an appropriate setting.

Has anyone else encountered a similar issue or even found a solution to this?

Thanks for any replies!

Share your automation(s).

This is certainly possible using a condition that monitors the switch binary sensor.

- id: '1642601782996'
  alias: Schalter Badezimmer AN
  description: ''
  trigger:
  - type: occupied
    platform: device
    device_id: c726ae9ce6f773b49afd95306cc03f42
    entity_id: binary_sensor.bewegungsmelder_bad_occupancy
    domain: binary_sensor
  condition:
  - condition: device
    type: is_on
    device_id: f806fb5aaf33c2a13ead86c6fa2ccd1f
    entity_id: switch.shelly1_badezimmer
    domain: switch
  action:
  - type: turn_on
    device_id: f806fb5aaf33c2a13ead86c6fa2ccd1f
    entity_id: switch.shelly1_badezimmer
    domain: switch
  mode: single
- id: '1642601864587'
  alias: Schalter Badezimmer AUS
  description: ''
  trigger:
  - type: not_occupied
    platform: device
    device_id: c726ae9ce6f773b49afd95306cc03f42
    entity_id: binary_sensor.bewegungsmelder_bad_occupancy
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
  condition: []
  action:
  - type: turn_off
    device_id: f806fb5aaf33c2a13ead86c6fa2ccd1f
    entity_id: switch.shelly1_badezimmer
    domain: switch
  mode: single

This is my current automation for the bathroom. I am guessing right that trigger type “is_on” should be subsittuted for something else? Unfortunately I dont know where to look up the yaml options for this device that are available.

Try not to use device automations. They are easy for beginners to understand but have major issues if you ever have to replace a device. Use the other options if you can. it is very easy to change an entity_id for a new device to match a replaced one. Much more difficult to change device ids.

e.g. try this instead:

- id: '1642601782996'
  alias: Schalter Badezimmer AN
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.bewegungsmelder_bad_occupancy
    to: 'on'
  condition:
  - condition: state
    entity_id: switch.shelly1_badezimmer
    state: 'on'
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.shelly1_badezimmer
  mode: single

- id: '1642601864587'
  alias: Schalter Badezimmer AUS
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.bewegungsmelder_bad_occupancy
    to: 'off'
    for:
      hours: 0
      minutes: 1
      seconds: 0
  condition: []
  action:
  - service: switch.turn_off
    target:
      entity_id: switch.shelly1_badezimmer

Thank you for your advice Tom. I will keep in mind to use entity states for my automations in future.

I also took your code and used it in my automations.yaml. Unfortunately it is still not working as expected.
The manual switch attached to it outside the wall still has no impact on the automation. It does toggle the light once however, as soon as you either leave the room or enter it, the lights will turn off/on, respectively.
The expected result would be to have the lights stay off when the switch is off and to automate when the switch is turned on.

Then you need to add the condition to both automations:

- id: '1642601782996'
  alias: Schalter Badezimmer AN
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.bewegungsmelder_bad_occupancy
    to: 'on'
  condition:
  - condition: state
    entity_id: switch.shelly1_badezimmer
    state: 'on'
  action:
  - service: switch.turn_on
    target:
      entity_id: switch.shelly1_badezimmer
  mode: single

- id: '1642601864587'
  alias: Schalter Badezimmer AUS
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.bewegungsmelder_bad_occupancy
    to: 'off'
    for:
      hours: 0
      minutes: 1
      seconds: 0
  condition:
  - condition: state
    entity_id: switch.shelly1_badezimmer
    state: 'on'
  action:
  - service: switch.turn_off
    target:
      entity_id: switch.shelly1_badezimmer

Hey Tom. Unfortunately this still isn’t working as expected. Its hard to tell whats going on, but I dont know how to start troubleshooting on my own. Is there such a thing as a list of yaml options for any given device? This way I could start playing around with automations.yaml and see how the automations react.

So I have tried everything but I still can’t get this to work properly. Its still the same situation. I am using

• Shelly 1

• Light switch attached to (SW)

• GU5.3 LED array attached to (O)

• Motion sensor logically attached via Home Assistant automation

The first 2 screenshots show how I configured the Shelly, the darker screenshot (in German) shows my options for setting conditions in Home Assistant.

The desired outcome would be

• to have the light go on automatically if I enter the room and off after a set period of time

• for the lights and the automation to stay off at all times if I toggle the switch which runs of (SW) to off

In reality, the motion sensor will always stay off. This makes sense because looking at the darker screenshot from my Home Assistant, it can be seen that my only option for a condition is “Shelly 1 is OFF / Shelly 1 is ON”.

In my understanding this refers to the relay and not to the switch.

So it basically says “turn the lights on if they are on” (which obviously does not help) am I correct?

What should I do to fix this?

Thanks for you help!



Try unticking this:

This is done by your automations, you don’t want the Shelly overriding it.

I tried @tom_l . Its still not working- this is so frustrating. I cant believe that this basic thing is causing me such headaches. Posted my question to the Shelly FB group aswell and wrote a mail to support. So far without luck either, since I believe Im being misunderstood.
To better illustrate my suspicion of what the cause of this problem is I attached 4 more pictures.

The 3 states of the standy button come from the Shelly web interface. They represent:

• Switch OFF + Relay OFF (Lights will be off)
• Switch ON + Relay ON (Lights will be on)
• Switch ON + Relay OFF (Lights will be off)

The other screenshot is the only entity that Home Assistant knows. Its the state of the relay- not of the switch!
However this entity is called switch.shelly1_bathroom.
Since there is only one entity available in Home Assistant, it is not possible to distinguish between switch state and relay state in automations. Thats where I believe things are going wrong.

Is this maybe something that can only be achieved with Zigbee2MQTT, NodeRED and Mosquitto, not with ZHA?

2022-01-31 15_38_04-Shelly1
2022-01-31 15_38_20-Shelly1
2022-01-31 15_38_32-Shelly1
2022-01-31 16_49_39-Shelly1

Go to the Home Assistant devices / entities page for the Shelly. You should see all the entities associated with the device. There should be a switch for the relay and a sensor for the switch.

Hey Tom. Okay something seems to be off here. I added screenshots again.
There were 2 hidden sensors that appeared to have no name. Clicking the bottom one for instance opened the popup window shown in the second screenshot. The text in red reads “This entity is not available.”
Do you think the device is faulty in this case?


No, it is just not enabled. Click the “Enable Entity” toggle button and then click update. Sometimes this requires a restart, sometimes a 30 second wait for the entity to be available. Home Assistant will tell you which.

Do this for both disabled sensors. I’m guessing one is the switch attached to the Shelly and the other is the Motion sensor.

Which leads me to ask what entities were you using in your automation?

Its finally working! I had no idea that there could be disabled entities. Such a fundamental insight, thank you Tom.

To answer your question: I am using a Philips motion sensor in conjunction with the Shelly 1. My automation now tells the Shelly to only turn on the lights if the Switch attached to it is set to “on”. Otherwise, to ignore any motion. So Im using the state of the motion sensor (Philips), the binary input sensor (Shelly) and the switch (Shelly)