Hi there
So this is my first time using the rest sensor and I am trying to get information from a website which requires username and password. Here is my configuration:
sensor:
- platform: rest
name: petrol
resource: https://app.petrolprices.com/map?fuelType=2&brandType=0&resultLimit=0&offset=0&sortType=price&lat=51.597033&lng=-0.349733&z=11&d=2
username: XXXX
password: XXXX
json_attributes_path: "$.next.*.properties"
value_template: "OK"
json_attributes:
- "name"
- "price"
headers:
Content-Type: application/json
The link/resource is basically the following data after logging in from my Windows 10 laptop on Chrome:
{"error":false,"limitExceed":false,"data":{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.317438,51.60131]},"properties":{"price":1587,"fuel_type":2,"user_id":1153383,"recorded_time":"2022-09-27T12:38:05.000Z","user_name":"nhroach1","idstation":1884,"fuel_brand":16,"fuel_brand_name":"ASDA","name":"BELMONT SERVICE STATION","address1":"BELMONT CIRCLE","address2":"BELMONT","town":"HARROW","county":"OUTER LONDON","postcode":"HA3 8SF","google":null,"phone":null,"open_hours":null,"Monday":null,"Tuesday":null,"Wednesday":null,"Thursday":null,"Friday":null,"Saturday":null,"Sunday":null,"distance_in_miles_from_given_coords":1.42,"reviews":{"count":2,"avg_rating":5}}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.393835,51.597948]},"properties":{"price":1599,"fuel_type":2,"user_id":1,"recorded_time":"2022-09-21T19:38:00.000Z","user_name":"news","idstation":606,"fuel_brand":2,"fuel_brand_name":"SHELL","name":"SHELL PINNER (SHELL PINNER)","address1":"PINNER GREEN","address2":"","town":"PINNER","county":"OUTER LONDON","postcode":"HA5 2AF","google":null,"phone":null,"open_hours":null,"Monday":null,"Tuesday":null,"Wednesday":null,"Thursday":null,"Friday":null,"Saturday":null,"Sunday":null,"distance_in_miles_from_given_coords":1.89,"reviews":{"count":11,"avg_rating":3.7273}}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.360183,51.587255]},"properties":{"price":1619,"fuel_type":2,"user_id":1,"recorded_time":"2022-09-21T05:38:00.000Z","user_name":"news","idstation":1658,"fuel_brand":3,"fuel_brand_name":"ESSO","name":"ESSO STATION ROAD (MFG TEN PIN)","address1":"STATION ROAD","address2":"NORTH HARROW","town":"HARROW","county":"OUTER LONDON","postcode":"HA2 6AE","google":null,"phone":null,"open_hours":null,"Monday":null,"Tuesday":null,"Wednesday":null,"Thursday":null,"Friday":null,"Saturday":null,"Sunday":null,"distance_in_miles_from_given_coords":0.81,"reviews":{"count":5,"avg_rating":3.8}}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.347973,51.581133]},"properties":{"price":1619,"fuel_type":2,"user_id":1,"recorded_time":"2022-09-21T12:30:00.000Z","user_name":"news","idstation":1655,"fuel_brand":2,"fuel_brand_name":"SHELL","name":"SHELL PINNER ROAD (MFG HARROW)","address1":"PINNER ROAD","address2":"WEST HARROW","town":"HARROW","county":"MIDDLESEX","postcode":"HA1 4EU","google":null,"phone":null,"open_hours":null,"Monday":null,"Tuesday":null,"Wednesday":null,"Thursday":null,"Friday":null,"Saturday":null,"Sunday":null,"distance_in_miles_from_given_coords":1.1,"reviews":{"count":4,"avg_rating":3}}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.337569,51.599686]},"properties":{"price":1629,"fuel_type":2,"user_id":1,"recorded_time":"2022-09-21T04:58:00.000Z","user_name":"news","idstation":1650,"fuel_brand":3,"fuel_brand_name":"ESSO","name":"ESSO HIGH STREET (MFG HIGH WEALD)","address1":"HIGH STREET","address2":"WEALDSTONE","town":"HARROW","county":"OUTER LONDON","postcode":"HA3 5EA","google":null,"phone":null,"open_hours":null,"Monday":null,"Tuesday":null,"Wednesday":null,"Thursday":null,"Friday":null,"Saturday":null,"Sunday":null,"distance_in_miles_from_given_coords":0.55,"reviews":{"count":3,"avg_rating":2.3333}}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.341778,51.579235]},"properties":{"price":1629,"fuel_type":2,"user_id":1,"recorded_time":"2022-09-20T19:13:00.000Z","user_name":"news","idstation":1881,"fuel_brand":1,"fuel_brand_name":"BP","name":"BP HARROW (BESSBOROUGH SF CONNECT)","address1":"BESSBOROUGH ROAD","address2":"","town":"HARROW","county":"MIDDLESEX","postcode":"HA1 3BS","google":null,"phone":null,"open_hours":null,"Monday":null,"Tuesday":null,"Wednesday":null,"Thursday":null,"Friday":null,"Saturday":null,"Sunday":null,"distance_in_miles_from_given_coords":1.28,"reviews":{"count":4,"avg_rating":4}}}]},"search_id":99796546,"message":"Petrol Station Fuel List Listed by Coordinates"}
On HA, it fetches the data from the resource/link but it does not log in to display the above data. I have made sure my username and password is correct but it doesnât work.
I have enabled the logging options in my configuration.yaml by doing this:
logger:
default: info
logs:
homeassistant.components.rest: debug
and my log is huge and it also shows the html code of the resource/link before logging in. I also see the following in my log:
2022-09-28 15:24:46.052 WARNING (MainThread) [homeassistant.components.rest.sensor] REST result could not be parsed as JSON
2022-09-28 15:24:46.058 DEBUG (MainThread) [homeassistant.components.rest.sensor] Erroneous JSON: <!DOCTYPE html>
Can anyone please point out what I am doing wrong and why is that I cannot log in to my link using the rest sensor on HA. Thank you.