Let’s break this down into components so that I can understand and then suggest/help.
NOTE: This is one way, I am sure there are many more. And I am not testing this, it may need a few tweaks. Also I tend to write things all directly in YAML, some of the like the automation you can build in the GUI editor.
- You have a sequence in which you want to run curl to http://yun.local/arduino/on
- You want some switch in the GUI to send that command
- You (have or will have) something like http://yun.local/ardino/status which would return the status
- It is not clear to me why you have an http://yun.local/ardiuno/off because you say it runs through a sequence and then ends (unless you want to be able to stop it at anytime)
What you need is 4 things.
-
An input_boolean (lets call it input_boolean.ardiuno for this exercise). As it is an input_boolean it has two states, it is either “on” or “off”. No YAML here, you can just use a helper to create it.
-
You have a shell_command that runs curl. Let’s call it shell_command.run_ardiuno. That would be very simply (you put you proper curl command here, below is just example):
shell_command:
run_arduino: >
curl http://yun.local/arduino/{{sequence}}
Note that you would be passing in the state of the switch here (“on” or “off” and hence I use a template to decide which URL to hit.
- You need a sensor that polls the state of the process. It should return JSON and could be very simple like
{"status": "running"}
of course here I am assuming you are writing this and will return your states that you wish (idle, running, emptying, filling, off)… YOu decide these but they should be states, I would say they are idle, running, emptying, filling … where idle is off. But that is your code. Think of the vacuum example never on or off, it is … docked, moving to target, cleaning, mopping, returning, emptying.
The sensor might be like this:
sensor:
- platform: rest
name: Arduino Status
scan_interval: 30
resource: http://yun.local/ardiuno/status
value_template: {{value_json.status}}
- Now you just need a automation that triggers on the change of the switch. Here you can do many things but I am only going to show you the “on” part as it is unclear if you want the “off” part.
alias: Run Ardiuno
description: ""
trigger:
- platform: state
entity_id: input_boolean.ardiuno
to: "on"
condition: []
action:
- service: shell_command.run_ardiuno
data_template:
sequence: {{ states('input_boolean.ardiuno') }}
mode: single
So when the switch goes on, run the command to turn on the sequence. Note that is uses data_template to send “on” or “off” from the state of the switch. The state of the sensor above is monitored all the time at 30 seconds, you can change that. You may want to add update entity on the sensor at the end to get immediate status change as the last step in that automation.
You probably also need to do something as a condition in the sequence like if the status moves to “off” or whatever you call it, it sets the input_boolean back to off.
What would be left is simply some Lovelace Entities card with the sensor and the input_boolean. It would show the switch for the input_boolean so you can click it and you can display the state of the sensor.
Now this is a solution which is poll based. It polls the process and reports back. You could implement it the other way and have a simple state sensor which you push the state into Home Assistant using its own REST API. That would be best if you do not want to use Home Assistant to start/stop things and always use something else. But I am assuming you want it all in Home Assistant and that is what this type of solution would provide.