Push a button via the REST API

coming form openHAB I still have troubles how to deal with certain things.
In openHAB I was able to send a turn ON to a entity via rest api. This way I could fire a rule (automation) which turned off the entity afterwards.

So in HA what is the best way to trigger a “button” in HA.
I like to have a button that is available in HA that when triggered starts an automation. I figured this one out and works great with an input_button helper.
Now I like to trigger the same button from external via the API is this possible?

Andy

Two rest commands:

One to turn on and one to turn off.

Then write a script that issues the on command, delay, off command.

Call the script whenever you want to push the button.

Thx but I did probably not explain it well enough.

I like to control an input_button in HA via the api from a curl command:
I have a input_button called “clean under table”. So when I press this in HA an automation is triggered that sends the vacuum to the table position.
Now I like to trigger the same automation via a rest api command via a curl command.
So how do I do that? Is it best to “push” the button via a REST API command? And if yes I did not yet figure out how to do that…

You’re looking for “POST /api/states/<entity_id>”

But it looks like you might be wanting webhooks, instead

I used this with -d '{"state": "ON"}' but I can only trigger an input_button once:

curl -v -X POST -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json" -d '{"state": "ON"}' http://xxx.xxx.xxx.xxx:8123/api/states/input_button.test

here the automation I use:

alias: TEST
description: ""
trigger:
  - platform: state
    entity_id:
      - input_button.test
    to: null
condition: []
action:
mode: single

of course another way would be to make a script that I can trigger with the API directly. And change the automation so that it launches the same script if the automation got trigerd by the input_button

My bad.
You actually want “POST /api/services/button/press

But once again, unless you really want the button for, e.g., UI, you want a webhook, here.

Sorry for bothering you again but it does not “press” the button

curl -v -X POST -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json" -d '{"entity_id": "input_button.test"}' http://xxx.xxx.xxx.xxx:8123/api/services/button/press

I get a HTTP/1.1 200 OK so it seems correct…

If you’re using an input_button, it should be /api/services/input_button/press, I missed that part.

oh man sorry for that and yes now it’s working!

hi
were u able to get it working?
i wasnt able to do it for button press
i use this POST command

POST /api/services/button/press HTTP/1.1
Authorization: Bearer xxxx
Host: 192.168.0.xxx
Content-Type: application/json
Content-Length: 51
{
  "entity_id": "input_button.test_sched_button"
}

i get response code 200 but the butoon in HA never presses or updates
I am able to set switch states w/o problem, so maybe im doing something wrong with push buttons?

image

1 Like

thank you! its working now!