I have device that uses API to report its status, when it goes offline, RESTsensor reports error, and to trying to make my HA error free, i have routed this offline state to file in my HA, this offline file works great, but problem is when going online again…
My device takes around 5min to report first JSON message, for this time my RESTsensor reports error and i want to get rid of this error.
To switch between online and offline address. I use resource_template in RESTsensor.
I have tried build in PING sensor, but this does not work for some reason for this specified address, i can get PING from device before it sends first JSON message but cant get PING from that “website” where JSON message is generated.
Currently i have Command Line binary_sensor and this works only some times, most of time this gives timeout error when device is online.
My sensor is
- binary_sensor:
scan_interval: 40
command: 'out=`curl -o /dev/null --connect-timeout 2 -w "%{http_code}\n" http://192.168.0.46/cgi-bin/api.py` && echo $out || echo 000'
name: "192.168.0.46"
unique_id: "unique_id_192-168-0-46"
device_class: connectivity
payload_on: "200"
payload_off: "000"
And error is
Timeout for command: out=`curl -o /dev/null --connect-timeout 2 -w "%{http_code}\n" http://192.168.0.46/cgi-bin/api.py` && echo $out || echo 000
Is my command wrong? I have copy-pasted that code from here forum and edited, i dont know much about command line comands currently.
Or should i use some other sensor/method