Home-assistant-fuel-scrapper
Fuel prices scraper for Home-assistant
This utility gets the results of a search in a website so you can scrappe the values and add them to your Home-assistant as sensors.
The values are scrapped from the portuguese national energy authority,which only has values for fuel shops in Portugal.
After scrapping the values, it writes them directly to your Home-assistant through it's API. This means that you don't need to enter anything in your configuration.yaml.
This script should be runned from a server on a dailly bases. Find out how to add it to a scheduller like crontab.
HOW-TO
First of all, you need to find out the identifier for the fuel shop you want to control
- Open Firefox or Chrome developer tools (Usually pressing F12 key).
- Select the network tab from the development tools so you can see the requests.
- Go to http://www.precoscombustiveis.dgeg.pt/
- Find the fuel shop you want info from.
- Click on the shop so you can see the info
- In the developer tools, on the network tab, select only the XHR traffic.
- Click on the POST to the infoPostoCB.aspx
- On the details for the request, read the parameters sent (Params).
- Take note of the value for nppostocombustivel.
Now, lets configure the bellow variables for your Home-assistant and fuel shop:
Home-assistant
PROTOCOL="http" <-- Enter either "http" or "https", depending where your Home-sistant is listening
HOST_IP_OR_NAME="localhost" <-- Usually "localhost" is fine. If you are running is script from another computer other than the one running Home-assistant, enter ther a named address like "myserver.myhouse" or an internet protocol number (IP) like "192.168.1.20"
PORT_NUMBER="8123" <-- This is the port number your Home-assistant is listening.
HAPASSOWRD="SomePassword" <-- You shouldnt leave you Home-assistant running thout a password. Enter yours here. Its the same password you entered for i_password: at configuration.yaml
Shoe Fuel shop friendly names in Home-assistnat
SHOWFUELSHOPLOCATION="nppostocombustivel nppostocombustivel nppostocombustivel" <-- In the first step you got this from the nppostocombustivel value. Enter each nppostocombustivel separated by a space.