Shelly 1 state without changing the relay

Hi Guys,

I recently installed a Shelly 1 behind one of my light switches and it works like a charm with a normal lightbulb.
Via MQTT I can now switch the relay to turn on or turn off the light independently of the state of the (wall)switch.

But what I would like to achieve is to use the shelly in combination with a smart bulb.
With the current configuration it switches off the power like a normal switch does and therefore the smartbulb loses its connection with (in my case) the tradfri hub.

When I change the button type in the Shelly interface to “ Detached Switch – switch is separated from the relays” it does not affect the relay, but I can’t seem to find a way to read the state of the switch to make a automation for example.

Does someone have experience with setting up the Shelly1 like the way i would like to use it? Or does someone have any tips?

2 Likes

Having the same question, hopefully someone knows.
I tried mixing all kind of settings but none does whatever I think it should…

It’s very easy. You have to change button type to detached switch and power on default mode to on in Shelly configuration.
In HA you have to move your smart bulb entity to the frontend (to turn on/of the light manually) and add automation:

- id: smart_bulb_toggle
  alias: 'Smart Bulb Toggle'
  trigger:
    - platform: state
      entity_id: binary_sensor.shelly_input_entity
      from: 'off'
      to: 'on'
  action:
    service: light.toggle
    entity_id: light.your_smart_bulb_entity

This is for momentary switch. If you have non-momentary switch:

- id: smart_bulb_turn_on
  alias: 'Smart Bulb Turn On'
  trigger:
    - platform: state
      entity_id: binary_sensor.shelly_input_entity
      from: 'off'
      to: 'on'
  action:
    service: light.turn_on
    entity_id: light.your_smart_bulb_entity

- id: smart_bulb_turn_off
  alias: 'Smart Bulb Turn Off'
  trigger:
    - platform: state
      entity_id: binary_sensor.shelly_input_entity
      from: 'on'
      to: 'off'
  action:
    service: light.turn_off
    entity_id: light.your_smart_bulb_entity

Of course you have to add binary_sensor.shelly_input to HA configuration. If you use my Shellies Discovery script it is already in HA.

3 Likes

Thanks for your response. But I think your solution works via a MQTT sensor. I found a state topic called “shellies/shelly1-******/input/0” which I configured as a template sensor.
When I physically flip the switch the state of the sensor changes from 0 to 1 but unfortunately the state changes with some delay.
Sometimes it will take up to 20 seconds before the state changes. And i want the lightbulb to switch on almost directly and the same goes for the light to switch off.
Does your solution work the same way?

My solution also use input/0 topic but with binary_sensor. Works immediately.

Forgive me… just stumbled onto this thread… but…

Why have a smart bulb in circuit that you have a Shelly controlling?
That defeats the point of the Shelly right?

With the Shelly… you can control the light with EITHER the manual switch OR the Shelly right?

What am I missing… GAWD knows since I started fooling around with HA Ive been asking ALLOT of dumb questions. LOL

THX

Some want to have light bulbs which are dimmable and can change color/hue. That way you can have a physical switch and the benefit of “smart” bulbs.

Oh… ok… so now I’m smarter!

thanks!

I installed your solution, but unfortunately it does not work all the time. Sometimes the binary sensor changes after 10 seconds, or not at all. And it’s weird because the relay switch works immediately but that’s the one i don’t want to use :smile:

It’s because i want to use the original phyiscal lightswitch but still be able to change brightness of the smartbulb. And i don’t want the smartbulb losing connection with the hub. If the bulb will not connect it will create errors in the zigbee network in my usecase.

Exactly that!

I found another solution. i used the MQTT broker within nodered.

Problem solved.

Thanks to your post I understand finally the binary sensors :slight_smile:
I tried to configure the same as you but for some reasons the phisical switches don’t work.
Can you tell me how to check what is wrong? Could the reason be that I 3 switches attached to my shelly 1?

Here are my configuration files:
binary_sensor.yaml ( I had already all my Shellies configured so I added this manually )

  - platform: mqtt
    name: Shelly Letto
    state_topic: "shellies/shelly1-941BFE/relay/0"
    payload_on: "on"
    payload_off: "off"

and automations.yaml

- id: yeelight_letto_on
  alias: 'Yeelight Letto ON' 
  trigger: 
    - platform: state 
      entity_id: binary_sensor.shelly_letto
      from: 'off' 
      to: 'on' 
  action: 
    service: light.turn_on 
    entity_id: light.camera_da_letto
 - id: yeelight_letto_off 
  alias: 'Yeelight Letto OFF' 
  trigger: 
    - platform: state 
      entity_id: binary_sensor.shelly_letto
      from: 'on' 
      to: 'off' 
  action: 
    service: light.turn_off
    entity_id: light.camera_da_letto

Btw in your example I see 2 light.turn_on service… I guess it’s wrong

You used wrong topic for the switch. You have to use input topic.
Of course second service should be light.turn_off.

sorry my noobness…
that would be:
state_topic: shellies/shelly1-941BFE/relay/0/command

shellies/shelly1-941BFE/input/0

You can do cool things with a shelly switch. I’m using a counter to count the times a wall-switch is turned over. And based on that number do some action.

In configurations.yaml:

counter:
  eettafel:
    initial: 0
    step: 1

sensor:
  - platform: mqtt
    name: "Lamp Schakelaar Eettafel"
    state_topic: "shellies/shelly1-111111/input/0"

Then the increment of the counter in an automation:

  - alias: Update Counter Eetafel
    hide_entity: true
    trigger:
      platform: state
      entity_id: sensor.lamp_schakelaar_eettafel
    action:
      service: counter.increment
      entity_id: counter.eettafel
    id: update_counter_eettafel

And the actions. Maybe it can be done in one automation, but this works :slight_smile:

  - alias: Turn on eetafel when counter is 1
    hide_entity: true
    trigger: 
      platform: state
      entity_id: counter.eettafel
      to: "1"
      for:
        milliseconds: 250
    action:
      - service: light.toggle
        data_template:
          entity_id: >
            {% if now().hour >= 6  %} light.eettafel
            {% elif now().hour >= 0 and now().hour < 6  %} light.lampjes_langs_plafond
            {% endif %}
      - service: counter.reset
        entity_id: counter.eettafel
    id: turn_on_eettafel_light_when_counter_is_1
  
  - alias: Control Lights With Switch Eettafel
    hide_entity: true
    trigger: 
      platform: numeric_state
      entity_id: counter.eettafel
      above: 1
      for: 
        milliseconds: 250
    action:
      - service: scene.turn_on
        data_template:
          entity_id: >
            {% if states('counter.eettafel') | int == 2 %} scene.woonkamer_uit
            {% elif states('counter.eettafel') | int > 2  and ( now().hour >= 12 or now().hour < 6 ) %} scene.woonkamer_lezen
            {% elif states('counter.eettafel') | int > 2  and now().hour < 12 and now().hour >= 6 %} scene.woonkamer_energie
            {% endif %}
      - service: counter.reset
        entity_id: counter.eettafel
    id: control_lights_with_switch_eettafel 

By turning the wall-switch one time, it just turns of the light connected to the wall-switch. If it is turned over more times within 250ms (this is fast enough on my NUC) it does some other stuff. Best part is turning the wall-switch over two times to turn everything of at the end of the day.

The last action of resetting the coutner is very important. Otherwise it will only work once.

Try it!

Nope… it’s not working anyway.
If you confirm me all is correct, then it means that you can’t use 3 switch configuration when detached option is activated. :frowning:

I finally understand why it wasn’t working.
Don’t know why but if I restart hass and the relay where you have the smartbulb (yeelight) isn’t on hass reboot, it cancel the smartbulb entity even if it’s manually configured.

Turning back on the topic…
3 Way Wallswitch configuration works, but sometimes I’m missing some switching and actually can’t understand what is causing it. Did also a check on the MQTT traffic and some input 0 came up without pressing.

After a few days of testing I can confirm that if the Shelly is set on detached mode and you have more than one wall switch connected to it you can’t use the input state for a sensor.

That’s why even if you switch on one of them, another swaps back the state to its position causing the change of the state.
I’ve got one smart bulb on a shelly with 3 way configuration and another on a 4 way. Should the input state be different to each switch you could set an automation that considers the toggling of one of them and reuse it for turning the smart bulb entity on but in this case I guess it’s quite impossible.

So unless someone denies what I’m writing I give up on this… Thank you anyway… I learned a lot these days.