Just want to share something that might help another Australian user.
I have a fibre to the premises broadband connection with a telstra provided Arcadyan LH1000 “smartmodem”. The modem fails over to 4G if the fibre drops. I wanted to know when this happens to investigate. No known api for the modem and I couldn’t find another technique, so I’m scraping the modem’s logon page to get the status of the link. I used phantomJS since I need to press a button before the status gets displayed properly.
First you need to install phantomJS somewhere on the Home assistant server.
I have:
the phantomJS script (above),
a shell script to run it and
a “command line” sensor defined in my configuration.yaml
yaml: [ change the directory and script name as needed]
sensor:
- platform: command_line
name: Internet Status
command: '/home/homeassistant/.homeassistant/phantomJS/monitor_telstra'
This shell script I introduced as I was occasionally having a null string returned (maybe when the router was slow in responding or timing out), It just reruns the scraping code if it gets nothing back. :
monitor_telstra shell script:
result=`/home/homeassistant/.homeassistant/phantomJS/bin/phantomjs /home/homeassistant/.homeassistant/phantomJS/monitor_telstra.js`
trimmed=`echo $result`
# if empty retry it
if [ -z "$trimmed" ]; then
#retry
echo `date` >> /tmp/monitor_telstra.log
sleep 3
result=`/home/homeassistant/.homeassistant/phantomJS/bin/phantomjs /home/homeassistant/.homeassistant/phantomJS/monitor_telstra.js`
trimmed=`echo $result`
echo $trimmed >> /tmp/monitor_telstra.log
fi
echo $trimmed
probably could do the “redo” logic inside the single phantomJS script to simplify.