Using CURL to connect via HA (MQTT service or light service) #378
erwin
started this conversation in
Show and tell
Replies: 1 comment
-
Thanks for sharing! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here's a brief reference for using
curl
to send commands to your OpenHASP devices if using Home Assistant.First you need a
Long-Lived Access Token
from Home-Assistant.Log in, click your own "Profile", scroll to the bottom and choose "Create Token"
Then you'll get a token like this:
(don't worry, I only generated that for these screenshots and have already deleted that token in my system).
To directly set values via the Home-Assistant
/api/services/light/turn_on
You'll need to start your script with something like:
(of course your value for BEARER has to be something that you generated on your home-assistant)
You also need to set HA_URL to the URL you actually use at home to connect to your home-assistant.
Then you can define a bash function like:
For example, to set the lights to RED, you would just use:
You just use a Red - Green - Blue value from 0 - 255
The home-assistant services that I use the most this way are:
"${HA_URL}/api/services/light/turn_on"
"${HA_URL}/api/services/light/turn_off"
"${HA_URL}/api/services/light/toggle"
"${HA_URL}/api/services/switch/turn_on"
"${HA_URL}/api/services/switch/turn_off"
"${HA_URL}/api/services/switch/toggle"
"${HA_URL}/api/services/homeassistant/turn_on"
"${HA_URL}/api/services/homeassistant/turn_off"
The latter two I mostly use for
input_boolean
values that I display on the OpenHASP screens.Home-Assistant ultimately forwards commands to OpenHASP via MQTT. It's also possible to send directly to MQTT via Home Assistant, though I have not benchmarked to see if the total system response time is faster or slower.
To send a request via curl throught the HA MQTT service, you can use:
You would just run:
If you're not very familiar with shell script, I would just create a new
openhasp.sh
file and paste the above in... On your command line just run:Then try to call the functions.
If you get an error, just edit the
openhasp.sh
file and runsource ./openhasp.sh
to update it and try again.Hopefully this helps you have more for on the command line and in your shell scripts connecting things to OpenHASP!
Beta Was this translation helpful? Give feedback.
All reactions