Change the state of a binary sensor?

I have a device that I control with a relay and an esp8266 and I want to be able to control it with both home assistant and a physical switch.
Currently, I am using Adafruit IO and it works fine but I want to move it to my home assistant using esphome.
I set up the switch on esphome as a binary sensor and it works fine until I turn on/off the dive via Hassio, then I have to turn the switch twice for it to work.

I think this is a very dumb problem but I am pretty new to Hassio and esphome and I don’t know how to fix this, can someone help me?

What is a fiscal switch?

What is your esphome yaml file?

What is a fiscal switch?

Physical?

Without seeing your actual configuration, it’s a bit of guesswork on what to do. However, given the description of your use case I would implement this as:

  • A switch component for the relay, which turns the relay output on and off, and which is exposed to Home Assistant.
  • A binary_sensor, connected to the physical switch, which togges the switch component in an on_press automation.

Relevant cookbook documentation page:

I hope this helps.

I meant physical, sorry for that

output:
  - platform: gpio
    pin: D0
    id: 'hidro'
switch:
  - platform: output
    name: "Hidro"
    output: hidro
binary_sensor:
  - platform: gpio
    pin: 
      number: D6
      mode: INPUT_PULLUP
    name: IN

I’ve already done that (I think)

I didn’t fully understand that, can you please explain me?

Untested, but would this work for you?

switch:
  - platform: gpio
    id: relay_switch
    name: "Hidro"
    pin: D0
binary_sensor:
  - platform: gpio
    id: physical_button
    pin: 
      number: D6
      mode: INPUT_PULLUP
    on_press:
      then:
        - switch.toggle: relay_switch

Main changes I did:

  • I used the gpio platform for switch, making the setup a bit simpler by removing the separate output.
  • I removed the name from the binary_sensor, and added an id in place of it. This will prevent the binary_sensor state from being published to Home Assistant (I presume there’s no need for that).
  • I added the on_press automation trigger to the binary_sensor, to toggle the relay when the physical button is pressed.

If the behavior of the button is erroneous, you might have to add some filtering to the binary_sensor to do debouncing → filter documentation

I think this works (at least it works on the protoboard).
I only changed the on_press for on_state science I am using a SPST switch

Thank you

Ah yes, on_press would be most inconvenient :yum:
Good luck!