Skons / hassio-addons

7 stars 4 forks source link

Not getting any fuel station #21

Closed MedicoreV8 closed 2 years ago

MedicoreV8 commented 2 years ago

I can't seem to get this to work and the manual isn't really that obvious for me either, I checked the closed issues to see if that could point me into the right direction but it didn't in the end. (for example: https://github.com/Skons/hassio-addons/issues/1)

Anyway, I installed the MQTT Broker and that is running too.

My config

log_level: info
ocr:
  contrast_enhance: 2
mqtt_port: 1883
mqtt_username: homeassistant
mqtt_password: [redacted]

configuration.yaml

[redacted]
# Includes - Links to other files
[redacted]
automation: !include automations.yaml
# Sensors
sensor:
# Buienradar sensor
[redacted]
# Gas stations sensor
  - platform: rest
    name: Gas stations within radius
    scan_interval: 600
    resource_template: http://127.0.0.l:5035/api/v1/gas_stations/euro98?radius=10&longitude={{ state_attr("zone.home", "longitude") }}&latitude={{ state_attr("zone.home", "latitude") }}
    method: GET
    json_attributes:
      - gas_stations
    value_template: >
      {% if (value_json.gas_stations[0].prijs) %}
        {{ value_json.gas_stations | length }}
      {% endif %}

[redacted]

automations.yaml

[redacted]
- alias: Update gas stations
  trigger:
    - platform: time_pattern
      minutes: 5 #every 5 minute past whole
  action:
  - service: mqtt.publish
    data:
      topic: 'dgp/gas_stations'
      payload_template: '{"fuel_type":"euro95","radius":10,"latitude":{{ state_attr("person.skons", "latitude") }},"longitude":{{ state_attr("person.skons", "longitude") }}, "to_publish":3}'
- alias: 'Shell: DFlaan'
  trigger:
    - platform: time_pattern
      minutes: 5 #every 5 minute past whole
  action:
  - service: mqtt.publish
    data:
      topic: 'dgp/gas_station'
      payload: '{"station_id":4059,"fuel_type":"euro95"}'
- alias: Notify lowest price gas station
  trigger:
  - platform: state
    entity_id: sensor.gas_station_[fuel_type]_lowest_price_1
  action:
  - service: notify.mobile_app_ios
    data:
      title: Cheapest gas station
      message: 'Gas costs € {{ states.sensor.gas_station_[fuel_type]_lowest_price_1.state }} at {{ state_attr("sensor.gas_station_[fuel_type]_lowest_price_1","station_street") }}. '
      data:
        url: https://www.google.com/maps/search/?api=1&query={{ state_attr("sensor.gas_station_[fuel_type]_lowest_price_1","latitude") }},{{ state_attr("sensor.gas_station_[fuel_type]_lowest_price_1", "longitude") }}

The Log:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Add-on: Dutch gas prices
 Get gas prices from dutch gas stations
-----------------------------------------------------------
 Add-on version: 2022.1.2.1
 You are running the latest version of this add-on.
 System: Home Assistant OS 7.4  (armv7 / raspberrypi4)
 Home Assistant Core: 2022.2.6
 Home Assistant Supervisor: 2022.01.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
Log level is set to INFO
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[17:19:09] INFO: Log_level: info
[17:19:09] INFO: mqtt_host: core-mosquitto
[17:19:09] INFO: mqtt_port: 1883
[17:19:09] INFO: Starting dutch gas prices...
[2022-02-14 17:19:10] INFO    : DGP initialized, launching client
[2022-02-14 17:19:10] INFO    : Connecting mqtt
[2022-02-14 17:19:10] INFO    : Connected with result code 0
[2022-02-14 18:05:00] INFO    : Received payload on topic 'dgp/gas_stations'
[2022-02-14 18:05:00] ERROR   : Unable to process payload: 'Expecting value: line 1 column 46 (char 45)'
[2022-02-14 18:05:00] INFO    : Received payload on topic 'dgp/gas_station'
[2022-02-14 18:05:05] INFO    : publishing station_id 4059 to mqtt
[2022-02-14 18:05:06] INFO    : Status Code  = 500

I tried to follow the manual but It's not really clear to me what I'm doing wrong here.

MedicoreV8 commented 2 years ago

extra info: I do have a zone configured around my home. the zone is called "Thuis" because I'm Dutch. not sure if that matters?

MedicoreV8 commented 2 years ago

Also: I did add one gas station on purpose to see if that would work. Doesn't pull any data though (not sure what status code 500 means)

Skons commented 2 years ago

First: this person probably does not exist on you ha instance: state_attr("person.skons This is in your automations, change this to the person ore zone from which you want the nearest gas station.

second: does gas station 4059 exist? (I cannot check that right now)

third: where did you get the rest sensor from? I cannot find it in the current documentation. That is the way it was done, but does not work anymore. It can be removed

last: can you enable debug logging? Redact passwords when pasting here, but it will contain hopefully more information in regards to your issues.

error 500 means internal server error and comes from directlease. Probably the input is not correct and means that your input is not correct. The addon can have better error handling which could point you to the real problem. I can take a look into that.

MedicoreV8 commented 2 years ago

I have changed state_attr from person.skons to person.[username] (hope that is correct)

Yes, 4059 exists, image

I got the rest sensor from a closed issue as I was hoping to find other people with the same problem. Didn't know it was deprecated, did cross my mind though.

Debug logging enabled, will report back in 5 minutes

MedicoreV8 commented 2 years ago

I don't think the automation has been triggered just yet. Here is the output of the log

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Add-on: Dutch gas prices
 Get gas prices from dutch gas stations
-----------------------------------------------------------
 Add-on version: 2022.1.2.1
 You are running the latest version of this add-on.
 System: Home Assistant OS 7.4  (armv7 / raspberrypi4)
 Home Assistant Core: 2022.2.6
 Home Assistant Supervisor: 2022.01.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
Log level is set to DEBUG
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[20:45:06] DEBUG: Requested API resource: http://supervisor/services/mqtt
[20:45:06] DEBUG: Request method: GET
[20:45:06] DEBUG: Request data: {}
[20:45:06] DEBUG: API HTTP Response code: 200
[20:45:06] DEBUG: API Response: {"result": "ok", "data": {"host": "core-mosquitto", "port": 1883, "ssl": false, "protocol": "3.1.1", "username": "addons", "password": "[Redacted]", "addon": "core_mosquitto"}}
[20:45:07] INFO: Log_level: debug
[20:45:07] INFO: mqtt_host: core-mosquitto
[20:45:07] INFO: mqtt_port: 1883
[20:45:07] DEBUG: mqtt_username: homeassistant
[20:45:07] DEBUG: mqtt_password: [Redacted]
[20:45:07] INFO: Starting dutch gas prices...
[2022-02-14 20:45:08] INFO    : DGP initialized, launching client
[2022-02-14 20:45:08] INFO    : Connecting mqtt
[2022-02-14 20:45:08] INFO    : Connected with result code 0
BebeMischa commented 2 years ago

You are aware of the fact, that after a restart of HA it always takes 10-20 minutes, before some results are showed? So with other words, are you waiting long enough before you think, it does no work?

It always generates some errors after a fresh start and results arrive within 20 minutes ;-)

MedicoreV8 commented 2 years ago

The first time I have waited a couple of hours. Right now, i have been waiting 15 minutes and counting. Will check back in 45 minutes

MedicoreV8 commented 2 years ago

It seems to return data now. This is the tail of the log https://pastebin.com/ZgVQ3MGe

I am however also seeing errors in my regular hass log: https://pastebin.com/pfdSmit5

Skons commented 2 years ago

You can run the actions of an automation by hand. By default it runs 5 minute paar the hole hour (check the automation you used 😉). If you want it different, you can change it 😊

MedicoreV8 commented 2 years ago

I am also getting some results on my lovelace dashboard with the default entities image

However, I have no way of telling which fuel pumps that is.

BebeMischa commented 2 years ago

in the first part of your automation you are missing this thing about the friendly name.

see my working code:

action:
  - service: mqtt.publish
    data:
      topic: dgp/gas_stations
      payload_template: >-
        {"fuel_type":"euro98","radius":5,"latitude":{{
        state_attr("person.mischa", "latitude") }},"longitude":{{
        state_attr("person.mischa", "longitude")
        }},"friendly_name_template":"[brand] ([station_street])",
        "to_publish":10}
Skons commented 2 years ago

It seems to return data now. This is the tail of the log https://pastebin.com/ZgVQ3MGe

I am however also seeing errors in my regular hass log: https://pastebin.com/pfdSmit5

Not all errors seem to be related though this isn’t correct amersfoortsestraat13(n23°_eur And sensor.gas_station_daam_fockemalaan18(n22_euro95.

i think this is an ocr error. I will look into that

You are getting results though. As you said, no way of knowing what is what. To solve this, read the manual on how to create a friendly name

MedicoreV8 commented 2 years ago

The dynamic discovery works with the friendly name template. Only thing left to resolve is the ocr error.

Skons commented 2 years ago

Ok, cool. And some documentation updates and error handling stuff