Need some help to set up "sensors" and "actors" via HTTP requests

I have just installed home assistant to my RPI4. It’s not something I’m familiar with. I’m very familiar with programming, designing and troubleshooting electronics, and experimentation. None of those things seem to be useful in this software. I feel I could really use some help.

My objective:

I have designed many sensors and actors that can be accessed via HTTP requests. I wish to show sensor values and be able to trigger actors with a button push as a starting point. Maybe later I can learn how to use some logic to automate (if-this-then-that).

Here is an example to read relay status on an 8-relay board:

This is a request. Although there’s no arguments, pretend other requests may have arguments sent via GET.
http://192.168.0.xxx/RELAY_status/

The response value is standard 200 while the response content is:
XXXXXXXX\n where each of the 8 X is either 1 or 0 indicating the relay is actuated or not.

I’d like to have home assistant send out this request at the push of a button and display the response.

What I’ve done so far.

Not much. I tried TCP which didn’t work because no requests were getting sent. I then tried shell_command which worked:

shell_command:
get_relay_status: curl http://192.168.0.XXX/RELAY_status/

I created a button card that runs this:


This looks stupid. I don’t have any entity and don’t even know why an entity is needed for a button. Doesn’t it just execute an action upon pushing? Anyway. I’m watching my relay HTTP server and can confirm that this shell command was sent successfully every time I push this stupid button.

What I need yet.
I wish to display the http response somewhere. I really don’t know where to start. Document on the shell_command is very bare. So is how something can be triggered using shell_command and response being displayed. An example would be very much appreciated.

And just in case you wonder, actor, this would turn on relay 1:
shell_command:
set_relay_status: curl blah/RELAY_actuate/relay1=on
Reading a pH sensor:
read_pH: curl blah/EZO_read/?addr=99
Response would be:
200 response code with content x.xx\n

I really wish to integrate this into: if pH is say greater than x.xx, turn on relay 1. Loop every say 10 seconds so the relay turns off once pH becomes less than x.xx.

Use the command line switch integration: Command line - Home Assistant

1 Like

I wish I could proceed but you must indulge with by elaborating how to “use”. The referenced document is just awful! A few lean examples are provided with next to no explanation. Is the value_template applied to the return value of command_on, command_off, or command_state because each one could be an http request with response text? I am guessing it is command_state based on vague descriptions at the top of the doc. Then what if I want to know if my command_on executed correctly? There is no programming logic in this. If command_on is considered a function of sort, isn’t it supposed to return values? Something I can easily process in a few lines of python or shell script looks so impossible to achieve here, i.e. send a command and read back response.

Yes the value template interprets the response of the state command.

A short time after your on of off command is sent a state command is sent to check if it executed correctly.

If you want more than this (e.g. a retry) then you will have to implement your own integration.