Best way to observe a shellscript-bool - without time-delay?

Hey All,

I have a shellscript running on the same device as HASS which gives a binary output.
I’d like to use this output for an automation.
For now I tweaked it to write the status in a temp file which is checked by HASS via the command_line sensor, simply running a cat on the file every 3 seconds.

Now 3 seconds can be an eterinity when it comes to toggling the lights so I’m looking for something like a RESTful way of pushing the information.
So far I have only found the TCP component and MQTT - both of which appear to be an overkill.
What’s the easiest way to implement something like this? Or to hack it? :wink:

Thanks,
bahmi

Use the rest api within the script to update a sensor?

1 Like

So I can simply create a “fake” binary_sensor (e.g. an entry in binary_sensor with only a name “mySensor” and not anything around) and then use the:

POST /api/services//

with the switch on/off ?
It didn’t even occur to me to use the native REST to be honest, no idea why. I’ll give it a shot tomorrow!

Thanks!

Without playing with it it may be a case of using an input_boolean rather than a binary sensor (and then hiding it from the UI)…

Thank you again, andrewdolphin!

I got it working fine and now the automation does exactly what I want :slight_smile:
Although I stumbled accross the input_boolean as well I didn’t find any examples for its use in automation although I guess it’s quite similar to other binary sensors.
In the next refactoring/learning round I’ll give it a shot!

And as I personally hate coming across forum posts which say “solved” but not how. (NOTE: The if part is unneccessary and a leftover of an experiment - will be reworked :slight_smile: )

  switches:
    doorbell_triggered:
      value_template: "{% if is_state('switch.doorbellstate', 'on')%}on{% else %}off{% endif %}" 
      turn_on:
        service: switch.turn_on
        entity_id: switch.doorbellstate
      turn_off:
        service: switch.turn_off
        entity_id: switch.doorbellstate                                  

As I didnt want to import HASSIO within python I used the requests lib.