Right. Now I feel very stupid.
So far I have managed to make a shell_command to send the POST request and even do some grep-ing to being parsing it.
Shell_command works absolutely fine - it’s just a curl command with grep - but I think I need to run it as a separate script to parse the data further (just using grep isn’t going to isolate the data I need sufficiently).
As mentioned, I’m running Hass.io on RPI 3B+ using the installation instructions at https://www.home-assistant.io/hassio/installation/
I have tried making a basic test.sh
in /config
like this:
#!/bin/bash
curl -XPOST -H 'Host: echo2.ectrecycling.co.uk' -H 'Connection: keep-alive' -H 'Content-Length: 496' -H 'Cache-Control: max-age=0' -H 'Origin: http://echo2.ectrecycling.co.uk' -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'Content-Type: application/x-www-form-urlencoded' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Referer: http://echo2.ectrecycling.co.uk/EchoServiceLookup/lookup.aspx?cid=33' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-GB,en;q=0.9' -H 'Cookie: ASP.NET_SessionId=vpjai445psbfaaqdan4bq245' -d '__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJNDg4NzU1NDU0D2QWAgIDD2QWCgIDDw8WAh4EVGV4dAUMQWxsIFNlcnZpY2VzZGQCBw8PZBYCHgdvbmZvY3VzBQ10aGlzLnNlbGVjdCgpZAIPDw8WAh8AZWRkAhEPPCsACwEADxYCHgdWaXNpYmxlaGRkAhMPPCsACwEADxYCHwJoZGRk3yoZMnyDgUF0FVLcP9fq%2FlXhjxY%3D&__EVENTVALIDATION=%2FwEWBQK2p8XABQKTitn8DAL7nPiqBwLhlb2gAgKHyYPoA4Z6zV37ftrM65ck3S9F854K%2BH9N&txtHouseNum=HOUSENUM&txtStreet=STREET&txtPostcode=POSTCODE&btnGetServices=Find+Address&hiddenInputToUpdateATBuffer_CommonToolkitScripts=1' 'http://echo2.ectrecycling.co.uk/EchoServiceLookup/lookup.aspx?cid=33' | grep 'Household'
And in configuration.yaml:
sensor:
- platform: command_line
name: test
command: "/config/test.sh"
But in the logger I’m getting:
2019-02-20 10:55:05 INFO (SyncWorker_6) [homeassistant.components.sensor.command_line] Running command: /config/test.sh
2019-02-20 10:55:05 ERROR (SyncWorker_6) [homeassistant.components.sensor.command_line] Command failed: /config/test.sh
Meanwhile, my shell_command
:
shell_command:
test: >-
curl -XPOST -H 'Host: echo2.ectrecycling.co.uk' -H 'Connection: keep-alive' -H 'Content-Length: 496' -H 'Cache-Control: max-age=0' -H 'Origin: http://echo2.ectrecycling.co.uk' -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'Content-Type: application/x-www-form-urlencoded' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Referer: http://echo2.ectrecycling.co.uk/EchoServiceLookup/lookup.aspx?cid=33' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-GB,en;q=0.9' -H 'Cookie: ASP.NET_SessionId=vpjai445psbfaaqdan4bq245' -d '__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJNDg4NzU1NDU0D2QWAgIDD2QWCgIDDw8WAh4EVGV4dAUMQWxsIFNlcnZpY2VzZGQCBw8PZBYCHgdvbmZvY3VzBQ10aGlzLnNlbGVjdCgpZAIPDw8WAh8AZWRkAhEPPCsACwEADxYCHgdWaXNpYmxlaGRkAhMPPCsACwEADxYCHwJoZGRk3yoZMnyDgUF0FVLcP9fq%2FlXhjxY%3D&__EVENTVALIDATION=%2FwEWBQK2p8XABQKTitn8DAL7nPiqBwLhlb2gAgKHyYPoA4Z6zV37ftrM65ck3S9F854K%2BH9N&txtHouseNum=HOUSENUM&txtStreet=STREET&txtPostcode=POSTCODE&btnGetServices=Find+Address&hiddenInputToUpdateATBuffer_CommonToolkitScripts=1' 'http://echo2.ectrecycling.co.uk/EchoServiceLookup/lookup.aspx?cid=33' | grep 'Household'
…works absolutely fine.
Is this a permissions issue? Have I not stated the correct filepath? Is my scripting rubbish? The error logs aren’t particularly helpful.
FULL DISCLOSURE: Whilst I can do stuff like SSH-ing in and certain amounts of debugging, I’m not very knowledgeable when it comes to understanding how exactly Hass.io is installed and run, standard permissions, docker environments and syntax for commands - so I apologise if I’m being stupid.
(P.S. hoping @123 sees this as I know they can point me in the right direction!)
EDIT: have also tried using #!/usr/bin/env bash
in the script and command: "~/config/test.sh"
in the sensor but no dice