Shelly 1 state without changing the relay

I was having an issue reading the state with a Shelly 2.5…would read the state as 0 and then revert to 1 even though the switch remained off. Updated the firmware and the problem resolved itself. Guess that was a bug they squashed. I can now accurately read switch state from the toggle switch in detached mode for both inputs (using input 0 for SW1 and input 1 for SW2).

I made an update…
In my case (with more than one switch attached, btw not momentary switches) the shelly will always check the state of the switchs every 30 seconds until you disable the “mqtt_update_period”.
You can disable it through http with this command
http://192.168.x.x/settings?mqtt_update_period=0
After doing this problem is solved… I’ve got only sometimes some missing switch and rarely ghost switching, but I’m sure it is caused by some bad coding in my configuration

1 Like

Thanks for this discussion. It was very useful to me.
There is one more thing I would like to do, but I’m not able.

If I turn on the smart bulb with the official app, the binary_sensor of the shelly remain logically to ‘off’. Is there any way to make it change to ‘on’ when I turn on the bulb from the app (and viceversa)? The binary_sensor is read-only right?

Thanks for the help
Regards

Create an input_boolean, which will be toggled by the Shelly through an automation. Then use the input_boolean to switch the bulb. But also switch the input_boolean based on the state of the bulb.

Ok. Thanks barrymossel! Good idea. I try. Just a doubt, when should I use the .turn_on / turn.off service and when .toogle?

turn_off: turns the switch to off
turn_on: turns the switch to on
toggle: turns the switch to on when off, and turns the switch to off when on

Everything’s working perfectly now.
Thank you very much @barrymossel

1 Like

Hello @kedante!

Would you mind to share your config for this with us? :slight_smile:

Hello @elektron303
Sure, here’s my code.

My light: light.luce_tavolo
hue light, discovered automatically
My shelly: shelly 2.5

A “binary_sensor” to read the status of the switch from Shelly:

- platform: mqtt
  name: "luce tavolo shelly relay 0"
  state_topic: "shellies/shellyswitch25-XXXXXX/input/0"
  payload_on: "1"
  payload_off: "0"

An “input_boolean” as recommended by barrymossel:

notifica_shelly_swicht_tavolo:
  name: notifica quando cambia lo stato dello switch del shelly tavolo
  icon: mdi:gesture-tap-button
  initial: off

And here all the automation, which use input_boolean as a “pivot”:

- id: 'luce_tavolo_da_shelly_a_boolean_on_off'
  alias: Cambia lo stato del boolean al cambiare dello switch shelly della luce tavolo da on a off
  trigger:
  - platform: state
    entity_id: binary_sensor.luce_tavolo_shelly_relay_0
    from: 'on'
    to: 'off'
  action:
    entity_id: input_boolean.notifica_shelly_swicht_tavolo
    service: input_boolean.toggle

- id: 'luce_tavolo_da_shelly_a_boolean_off_on'
  alias: Cambia lo stato del boolean al cambiare dello switch shelly della luce tavolo da off a on
  trigger:
  - platform: state
    entity_id: binary_sensor.luce_tavolo_shelly_relay_0
    from: 'off'
    to: 'on'
  action:
    entity_id: input_boolean.notifica_shelly_swicht_tavolo
    service: input_boolean.toggle

- id: 'luce_tavolo_da_stato_luce_a_boolean_on_off'
  alias: Cambia lo stato del boolean al cambiare dello stato della luce tavolo da on a off
  trigger:
  - platform: state
    entity_id: light.luce_tavolo
    from: 'on'
    to: 'off'
  action:
    entity_id: input_boolean.notifca_shelly_swicht_tavolo
    service: input_boolean.turn_off

- id: 'luce_tavolo_da_stato_luce_a_boolean_off_on'
  alias: Cambia lo stato del boolean al cambiare dello stato della luce tavolo da off a on
  trigger:
  - platform: state
    entity_id: light.luce_tavolo
    from: 'off'
    to: 'on'
  action:
    entity_id: input_boolean.notifca_shelly_swicht_tavolo
    service: input_boolean.turn_on

- id: 'luce_tavolo_on'
  alias: Accendi luci tavolo
  trigger:
  - platform: state
    entity_id: input_boolean.notifca_shelly_swicht_tavolo
    from: 'off'
    to: 'on'
  action:
    service: light.turn_on
    entity_id: light.luce_tavolo

- id: 'luce_tavolo_off'
  alias: Spegni luci tavolo
  trigger:
  - platform: state
    entity_id: input_boolean.notifca_shelly_swicht_tavolo
    from: 'on'
    to: 'off'
  action:
    service: light.turn_off
    entity_id: light.luce_tavolo

Ciao
Dante

3 Likes

Thank you so much @kedante :slight_smile:

You’re welcome.
I still have a little problem, when I reboot hassio, sometimes the lights go on. I don’t understand why.

Can You share how You did that in Nodered?

@banolka
I have made an automation in Node-Red to turn on the light with the physical switch without changing the relay. Before this I have used the YAML code that Kedante provided.
It’s actually quite easy to make this work in Node-Red. Much easier than in YAML.

I have added the Boolean sensor and the Input sensor like Kedante. After that I checked a state change of the Input sensor. If a state change is detected it toggles the Boolean sensor.
I then checked for the state change of the Boolean sensor and connected that to a call service node that turns on my Yeelight smart bulb.

You can turn on and off with the switch and turn on and off though the app. There is no double switching with the physical switch.
Look at the attachments at how my Node-Red flow looks like.Node Red automation

Hi @Bieniu! I am new to home automation and I am using your Shellies Discovery script which is really great! Thank you very much! I also used the non-momentary switch automation you shared above and it works for me when HA is running (Shelly 1 is configured Button Type: Detached Switch and Power On Default Mode: On). However, when HA is turned off, the physical switch cannot be used to turn on/off the smart bulb which is connected to HA via deCONZ/ConBee II integration. Is there a way to use the physical switch + Shelly 1 with a smart bulb, with and without HA running? I am just worried that I will not be able to turn on my lights when there is a problem with my HA installation.

If you use bulbs with rest interface (e.g. Shelly Bulb) you can send rest command from Shelly1 to the bulb. If you use smart bulb without rest interface I think it’s not possible.

Thanks, @Bieniu. I’m using IKEA bulbs so I guess I can’t use rest commands. But your response gave me an idea for a temporary workaround. I created rest commands in configuration.yaml to change the Button Type to “Toggle Switch” and Power On Default Mode to “Switch” which, using automations, are sent to the Shelly1 when HA is shutdown. This works when HA is cleanly shutdown. For a permanent solution, I am now looking to apply this in an external watchdog to monitor if HA is not running; then the watchdog will send the rest commands to the Shelly1.

I found this thread because i am looking to do something similar. I am using the Shelly integration (which may be the issue) and I have my shelly 1 with the switch in detached mode. However I do not see a binary_sensor input for the switch in home assistant. Do you have to use MQTT integration for this to work?

I noticed this missing for the Shelly1 also.
Went back to MQTT.

At the moment official Shelly integration doesn’t support input sensors. You have to use MQTT (e.g. Shellies Discovery script) or ShellyForHass.

Thank you for telling me about ShellyForHass I did not see that add on, looks pretty good I will be trying it out.