How can I send a command to HA from phone or computer?

Hi friends!

Till new I managed to send commands from HA to EventGhost (pc) and to Tasker (android). But I don’t know how to send a command from PC or Android device, to HA to execute something. Can someone please help me with this?

PLEASE, no IFTTT solution, I want to get rid of this service :slight_smile:

Thank you!

You can access HA by api to send specific command by http

You may also use MQTT

I don’t understand much from that link, I forgot to specify that i’m maximum noob :slight_smile: I am using HA for one day only. Can you please tell me, if you have time, of course, step by step, what I should to on HA and how can I send command from pc to HA? It will really help me

Can’t you use the companion app?

It is in that link but from PC you can use something like curl from the command line. Call that from whatever you want, batch file, eventghost. There are examples in this link.https://developers.home-assistant.io/docs/api/rest/

Download curl for your PC: https://stackoverflow.com/questions/9507353/how-do-i-install-and-use-curl-on-windows
You have to create a bearer token in HA to replace (ABCDEFGH) below.

curl -X POST -H "Authorization: Bearer ABCDEFGH" \
  -H "Content-Type: application/json" \
  -d '{"entity_id": "switch.christmas_lights"}' \
  http://localhost:8123/api/services/switch/turn_on

For android you can use tasker’s HTTP POST with the same values:
https://tasker.joaoapps.com/userguide/en/help/ah_http_post.html

1 Like

Hoorayyyyy, I managed to turn on one switch with autohotkey, by doing this

req := ComObjCreate(“WinHttp.WinHttpRequest.5.1”)
req.open(“POST”, “xxxxxxxxx/api/services/switch/toggle”)
req.SetRequestHeader(“Content-Type”, “application/json”)
req.SetRequestHeader(“Authorization”, “Bearer xxxxxxx”)
req.send("{"“entity_id”": ““switch.sonoff_xxxxxxx””}")
MsgBox, % req.ResponseText

I use the RESTask plugin with Tasker to send commands to HA from Android. For example, when I put my phone on to charge after 10pm, send the command to initiate the Bedtime scene. I’ve even made it generic using parameters and variables.

RESTask configuration - Settings

Request type: POST
Host: %HASS_URL/api/services/%par1 (%par1 is the service name passed from calling task such as “scene/turn_on”)
Return code: %rtcode
Response: %rtres
Custom body: %par2 (contains json such as “entity_id”:“scene_bedtime”)

RESTask configuration - Headers

Authorization

Bearer %HASS_Token (contains value of long-lived token)

I do it with the home assistant plugin for tasker, but it is very clean with the HTTP Request from tasker as well…

But I will try this plugin as well, seems friendly. Thank you for your advice!