How to toggle an `input_button` from ESPHome?

I defined an Input boolean entity in Homeassistant. I have an ESPHome connected with a Nextion display, and I would like to toggle the status of the input_boolean from the display.

I tried using a homeassistant.service action to turn_pff/turn_on the input_boolean. Developer tools shows the following as a valid YAML snippet:

service: input_boolean.turn_on
data: {}
target:
  area_id: furdo
  entity_id: input_boolean.teregetesre_var

while ESPHome’s homeassistant.service does not support the target attribute, so I can not use it, I guess.

How can I trigger the input_boolean.turn_on service from ESPHome with the target I need?

1 Like

Try this:

service: input_boolean.turn_on
data:
  entity_id: input_boolean.teregetesre_var
1 Like

I know this is an old thread but it’s the nearest I could find to my problem

I call an ESPHome script from HA using a HA input_boolean via a binary_sensor in ESPHome.

  - name: "Set house alarm night"
    platform: homeassistant
    entity_id: input_boolean.set_house_alarm_night # Defined in homeassistant
    id: set_house_alarm_night

When the ESPHome script has finished I want to turn off the HA input boolean.

Can this be done?

Of course it can. You should always check the documentation to see if its already a configuration option…

Your best choice woud be to just clean up your code and make it efficient. Thats what you call, “going in circles” and you likely dont need most of those entities. Probably just the script and binary sensor.

Post the relevant code and lets get you straightened out!

Thanks for the reply.

I need the feedback loop to tell me that the script has completed.

If there’s a way to negate the binary sensor in ESPHome and access the state of the input_boolean by another means that would be great.

I thought using a binary_sensor with homeassistant as the platform was the only way to trigger the script from Home Assistant.

Your screenshot shows a Switch: being used instead of a binary_sensor. I’m not sure how that is different.

I think my thinking is going around in circles now. All I really need to know is how can I turn off a Home Assistant inupt_boolean from ESPHome.

Its hard to really say anything with certainty until you post the code and i can see what your doing or trying to do.

There’s a really high chance that there are multiple better ways and each different. This is why i need to see the code. There are dozens of ways to trigger a script and no offense but yours is all messed up and mixing HA entities into an esphome device so that you add unnecessary risk of failure or reliability, its a bad idea. If Esphome has a large number of comparable entities to use because its meant to be able to operate 100% independent of HA so, you really shouldn’t be using input_boolean from HA at all here.

If you step back and think about it, what is an input_boolean? Its essentially a 2 state digital latching switch and uses True/False just as a switch/button uses On/Off or True/False too.

Here part of the binary_sensor documentation and look at that,it uses True/False by default and will make a perfect alternative to HA input_boolean.

For anyone else needing to do this, the solution is quite simple, now that I know!

My goal was to be able to turn on or off a Home Assistant input_boolean from an ESPHome script.

Firstly, ensure that the following checkbox is checked in your ESPHome devices config:

Then add the following lines to your ESPHome script (or anywhere else that you may need to use it) in ESPHome:

script:
  - id: home_set
    then:
      - homeassistant.action:
          action: input_boolean.turn_on
          data:
            entity_id: input_boolean.test_boolean
.
.
Rest of script goes here
.
.
      - homeassistant.action:
          action: input_boolean.turn_off
          data:
            entity_id: input_boolean.test_boolean

Works like a charm.

There’s a reason you had a hard time finding information with people doing this and its because you shouldn’t even be using an input_boolean because its not a good option and for several reasons.

You’ll figure out why sooner or later…