Skons / hassio-addons

7 stars 4 forks source link

'Gas stations based on id' seems to report 'Unknown' #44

Closed jellewie closed 1 year ago

jellewie commented 1 year ago

Running an automation with

service: mqtt.publish
data:
  topic: dgp/gas_station
  payload_template: "{\"fuel_type\":\"euro95\", \"station_id\":6323 }"

Which has the logs:

[2023-04-16 13:08:51] INFO    : Received payload '{"fuel_type":"euro95", "station_id":6323 }' on topic 'dgp/gas_station'
[2023-04-16 13:08:51] DEBUG   : station: Station id '6323' from cache
[2023-04-16 13:08:51] DEBUG   : station '6323': return value '{'station_id': 6323, 'price': 1.859, 'fuel_type': 'euro95', 'station_street': 'Zonnelaan 389', 'station_address': '9742 BK Groningen', 'timestamp': '2023-04-16T10:27:40.571431+00:00', 'status': 'Ok', 'processing_start': '2023-04-16T11:08:51.450526+00:00', 'processing_time': 0.02, 'brand': 'Shell', 'name': 'Paddepoel', 'latitude': 53.235381, 'longitude': 6.539301, 'fuel': 'euro95'}'
[2023-04-16 13:08:51] INFO    : publishing station_id 6323 to mqtt
[2023-04-16 13:08:51] DEBUG   : on_message: received the topic 'homeassistant/sensor/dgp_gasstation/6323_euro95/config'
[2023-04-16 13:08:52] DEBUG   : publish_station: Waiting for discovery on topic 'homeassistant/sensor/dgp_gasstation/6323_euro95/config'
[2023-04-16 13:08:52] DEBUG   : publish_station: Setting sensor values to url 'http://supervisor/core/api/states/sensor.gas_station_6323_euro95' with token
[2023-04-16 13:08:52] DEBUG   : Starting new HTTP connection (1): supervisor:80
[2023-04-16 13:08:52] DEBUG   : http://supervisor:80 "POST /core/api/states/sensor.gas_station_6323_euro95 HTTP/1.1" 200 726
[2023-04-16 13:08:52] DEBUG   : publish_station: Status Code  = 200

Results in an 'Unknown' sensor value? image

A script with a radius does seem to work. but it seems you can't have two of those. They will overwrite each other. so It is not useful in my use case.

Am I doing something wrong with the payload_template config, or is there a small bug somewhere?

Skons commented 1 year ago

This is my first try on this station, and i get this result image

[2023-04-17 23:34:07] INFO    : Received payload '{"fuel_type":"euro95", "station_id":6323 }' on topic 'dgp/gas_station'
[2023-04-17 23:34:07] DEBUG   : station: Station id '6323' new request
[2023-04-17 23:34:07] DEBUG   : Starting new HTTPS connection (1): tankservice.app-it-up.com:443
[2023-04-17 23:34:07] DEBUG   : https://tankservice.app-it-up.com:443 "GET /Tankservice/v1/places/6323.png HTTP/1.1" 200 None
[2023-04-17 23:34:08] DEBUG   : _write_stationdata: draw logo coverup with coordinates x0: '668', y0: '0', x1: '908', '200'
[2023-04-17 23:34:08] DEBUG   : _write_stationdata: Enhancing contrast with '2'
[2023-04-17 23:34:12] DEBUG   : _write_stationdata: OCR lines detected '['Zonnelaan 389', '9742 BK Groningen', 'Brandstof', 'Euro 95 (E10) €1,85°', 'Diesel (B7) €1,56°', 'V-Power Benzine (E5) € 2,16°', 'V-Power Diesel €1,80°', 'Voorzieningen', 'Winkel', '@ Autowasgelegenheid', 'a Internet beschikbaar', 'Q Aanhangwagenverhuur', 'Openingstijden', 'Maandag t/m vrijdag: 6:00-22:00 uur', 'Zaterdag: 7:00-22:00 uur', 'Zondag: 8:00-22:00 uur', '\x0c']'
[2023-04-17 23:34:12] DEBUG   : gas_station: Fuel 'euro95' new request
[2023-04-17 23:34:12] DEBUG   : Starting new HTTPS connection (1): tankservice.app-it-up.com:443
[2023-04-17 23:34:12] DEBUG   : https://tankservice.app-it-up.com:443 "GET /Tankservice/v1/places?fmt=web&fuel=euro95 

If you are requesting a seperate station, it will be published to another sensor as when you are requesting withing a radius. So those two should not bite each other. If a station is requested within a radius and afterwards within 1 hour direct, you get data from the cache. That difference can be seen between your log and mine. But the data is the same.

Can you show me a screenshot of the entity instead of the graph?

jellewie commented 1 year ago

image

thank you for asking, I found the issue. It seems it made a bunch of MQTT entities too But those do not work, the other name you suggested works (and I got this from your screenshot)

Not working created entity: sensor.gas_station_zonnelaan_389_euro95 Working name: sensor.gas_station_6323_euro95

I do not know why it made these not working entities, maybe that part can be looked in to?

Skons commented 1 year ago

I have seen these at my instance, but i cannot reproduce it. I do not yet know what caused them

jellewie commented 1 year ago

It seems when you disable them, the other values do not get updated. so they seem to hang together even after creation

Skons commented 1 year ago

I can reproduce this issue, i don't know why it did not seem to work earlier. If you request a station by id, you will always get the entity you showed in your screenshot. This seems to be something within HA, because i never publish to that entity. It is probably created automatically. I will have to look into how HA uses the payload to create entities, i think i have to reconfigure the way the data is published to mqtt.

Skons commented 1 year ago

Just updated to version 2023.4.26.1 which solves your issue. My naming convention was all over the place. Fixed that :). You can delete the unknowns safely, sometimes a reboot is needed