I am using Home Assistant for years and it became de facto my state machine for everything in home automation but also in my own development around my self-hosted world.
Over the years I moved more and more activities to the native HA solutions (for instance automation: I started with the HA YAML, moved to App Daemeon, moved to my own docker with automations, moved to pyscript and then finally came back to the native automations - a several years journey).
I now face the question of launching some simple scripts (calling an API, checking on the reply, polling for state - and the script ends after having set some states). My first goto solution is to use pyscript but I was wondering if in the “new” (= say, a year or two) HA there wouldn’t be a better (simpler/more native) solution?
This is a general “call for ideas” - I will manage on my own, just did not want to miss something.
TL;DR: what would you use to run simple scripts such as “action an IoT and set a state upon the reply”
Note: I specifically do not want to use MQTT for this script, for a bunch of reasons
what do you mean 'set a state on reply'? Setting states isn’t really a thing in HA unless you use these ‘other’ automation engines. Typically, if you’re setting a state, you should be using template sensors.
with built in HA, you can make a script return a value. You can use that in the action field on a trigger based template sensor.
Sorry for not having been more clear. To set the context, this is an example of the action I had in mind (for instance opening a sliding door that opens slowly):
call an API
set a state “calling”
wait for a reply
analyze the reply
depending on the reply set the state to “failed” or “started”
call the API to get the status of the opening (in a loop)
set the state to “opening” or “open”
when the state is “open” we are done
This could be triggered in an automation (a physical button was pressed, a helper button was pressed, the sun is up, …)
The simple case of “call and API and that’s all” can be done though rest_command but the more complicated polling probably not.
It would not be difficult to do in pyscript, I was just considering something more native.
Combination of Script and rest_command should do it? Might be better organised as more than one discrete script (e.g. the polling loop, if there’s no better way to get the state back).