Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App doesnt update without reloading service. #25

Closed
4 tasks done
utzy79 opened this issue Nov 8, 2024 · 25 comments
Closed
4 tasks done

App doesnt update without reloading service. #25

utzy79 opened this issue Nov 8, 2024 · 25 comments

Comments

@utzy79
Copy link

utzy79 commented Nov 8, 2024

System Health details

.

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of any previous issues..

Describe the issue

Hi there. Great app, been looking for something like this for years. But for some reason the priced dont update unless i reload the service manually.
I am assuming that this is not normal behavior but I cant seem to work out why?
I would be happy to have an automation that reloads the service, but cant seem to work out how to do that either without reloading all services.

Reproduction steps

...

Debug logs

.

Diagnostics dump

No response

@pantherale0
Copy link
Owner

Hi,

You shouldn't need to reload the integration to update data, although by default the refresh interval is set to 12 hours (I believe).

If you open an entity you should be see a Last updated attribute and Next update, can you check that those two attributes have updated after the next occurrence of Next update please?

image

@Rotil66
Copy link

Rotil66 commented Nov 15, 2024

Hi All,
I also have installed the integration and run into the same problem. I have seen that all the entities have a last update and a next update value that is corresponding with the set update interval, exept the Entities sensor.cheapest 1,2,3,4,5 Here in the attributes the last update is 'undefined' and the 'next-update'is set to the date that the intergation is started not to the next interval time.
So it never updates anymore. This looks like a 'bug' or I am doing something wrong. The sensor for the cheapest stations is the one you want to use offcourse.
Is there a solution to this ??

Thanks

@PeteLawler
Copy link

I'm wondering if the lack of update you're both seeing is same as the reason I'm not seeing an update.

In my logs, I'm getting this error. Whether it's the cause, I cannot say. The only reason I think it might is that clearly the update callback is failing. I had the Cheapest stuff enabled, but even turning it off didn't seem to fix the problem.

Error doing job: Task exception was never retrieved (None)

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 266, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 481, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 176, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 561, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1007, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    self.__async_calculate_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1073, in __async_calculate_state
    if extra_state_attributes := self.extra_state_attributes:
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/fuel_prices/sensor.py", line 167, in extra_state_attributes
    return {
           ^
TypeError: 'NoneType' object is not a mapping

@utzy79
Copy link
Author

utzy79 commented Nov 20, 2024

I have found a work around for this,
You need to create an automation that refreshes the service. Refer below

alias: Reload Fuel Prices app Every hour
description: ""
triggers:

  • trigger: time_pattern
    hours: /1
    conditions: []
    actions:
  • action: homeassistant.reload_config_entry
    metadata: {}
    data:
    entry_id: 01JC4K3HKRZRQTZ8EAVD9GKRPA
    mode: single

For the entry ID you need to go into E:.storage\core.config_entries
within this file search for
"fuel_prices","entry_id"

image

Next to this will be the code you need for entity ID.

@Rotil66
Copy link

Rotil66 commented Nov 20, 2024

Hi Utzy,
Thanks for this info. I will give it a try as soon as possible. Would be great if this works, so I can use the info as intended.

Thanks!

@pantherale0
Copy link
Owner

Hi all,

Will work on solving this asap. It's something I've come across too in testing, but I actually don't use this feature, instead I have a template sensor with an automation that pulls the cheapest fuel stations near where I currently am (based on phone location).

@Rotil66
Copy link

Rotil66 commented Nov 20, 2024 via email

@stevephi59
Copy link

Hi Utzy,

Thank you for the work around, is working for me.


@ALL
Do the cheapest station sensors also order by distance when a number of stations have the same price? Mine seems to list the furthest away first to the closest listed last - is this correct, am I able to invert the order?

Thanks and Regards

@pantherale0
Copy link
Owner

Thank you for the work around, is working for me.

I need to warn, some providers are known to implement rate limits and block IPs if exceeded. Manually reloading the integration will override the update intervals.

It's not something I can recommend is done too frequently (hence the update interval in the config wizard has a lower limit of 3 hours I believe).

@Rotil66

This comment has been minimized.

@utzy79

This comment has been minimized.

@Rotil66

This comment has been minimized.

@utzy79

This comment has been minimized.

@Rotil66

This comment has been minimized.

@Rotil66

This comment has been minimized.

@Rotil66

This comment has been minimized.

@pantherale0
Copy link
Owner

@Rotil66 @utzy79 please continue this discussion either in Discord, the HA forums or in the discussion page of this repository. I've marked these comments as off topic because they have moved the discussion away from the actual issue itself.

@pantherale0
Copy link
Owner

Hi Jordan, this is something I'm also looking for. Are you willing to share this with me/us. thanks ⁣BlueMail voor Android downloaden ​ Op 20 nov 2024 12:02, om 12:02, Jordan Harvey @.***> schreef:

Hi, please find below template sensor configuration (to be used in the templates section of your configuration.yaml file).

- trigger: 
    - platform: state
      entity_id:
        - <sensor entity ID with long>
      attribute: longitude
    - platform: state
      entity_id:
        - <sensor entity ID with lat>
      attribute: latitude
    - platform: homeassistant
      event: start
    - platform: state
      entity_id:
        - input_button.force_update_fuels
        - input_boolean.use_cheapest_station
  action:
    - service: fuel_prices.find_fuel_station
      data:
        location:
          latitude: |
            {{ state_attr('<sensor entity ID with lat>', 'latitude') | float }}
          longitude: |
            {{ state_attr('<sensor entity ID with long>', 'longitude') | float }}
          radius: |
            {{ 5 * 1609.34 }}
      response_variable: data
    - variables:
        data: >
          {% if states('input_boolean.use_cheapest_station') == 'on' %}
            {{ data['items'] | sort(attribute='available_fuels.<fuel type code>') }}
          {% else %}
            {{ data['items'] | sort(attribute='distance') }}
          {% endif %}
  sensor:
    - name: Nearest Fuel Station
      unique_id: Nearest Fuel Station
      state: |
        {{ data[0].available_fuels.<fuel type code> | float }}
      availability: |
        {{ data | count > 0 }}
      state_class: measurement
      device_class: monetary
      unit_of_measurement: GBP
      attributes:
          other_stations: |
            {{ data }}
          latitude: |
            {{ data[0].latitude }}
          longitude: |
            {{ data[0].longitude }}
          name: |
            {{ data[0].name }}
          station: |
            {{ data[0] }}

Items that should be replaced for your liking:
<sensor entity ID with lat> = a device tracker or sensor that contains GPS coordinates
<sensor entity ID with long> = same as above
<fuel type code> = The fuel type to use (key as displayed in the entity attributes, diesel in the UK for example is B7 but other countries will be different.

@pantherale0
Copy link
Owner

This should now be fixed in 2024.11.2

@Rotil66
Copy link

Rotil66 commented Nov 22, 2024

Thanks Jordan, I will add your code and see if It's updating the fuel prices without the workaround 👍🏻 Great work!!

@Rotil66
Copy link

Rotil66 commented Nov 23, 2024

Hi Jordan,
I have 2024.11.4 running but as far as I can see the prices are still not updated.
In attributes for cheapest stations the next next update is set to the date the service started and the last update is stil ' undefined'.
Will check longer but the issue seems remain.

@stevephi59
Copy link

Hi Rotil66,

If anything mine is updating the cheapest stations far too often, seems to be every 5 minutes. Maybe unrelated but I have also installed Jordan's template sensor.
I had also deleted the configuration before installing 2024.11.2 and recreated it afterwards. I had done this to try and overcome an error which suddenly started to appear after a reload of HA - error communicating with the API. I think my problem was with BP UK, however everything worked as expected after installing the latest code.

fuel_prices_20241123_132632
fuel_prices_20241123_132821

@pantherale0
Copy link
Owner

If anything mine is updating the cheapest stations far too often, seems to be every 5 minutes. Maybe unrelated but I have also installed Jordan's template sensor.

This is intended, the update interval is set to every 5 minutes at the moment, to note, this is only from the location cache, no web requests should be sent unless the data source needs an update (as defined in the update interval).

@Rotil66
Copy link

Rotil66 commented Nov 26, 2024 via email

@pantherale0
Copy link
Owner

@Rotil66 please open a new issue.

Repository owner locked as resolved and limited conversation to collaborators Nov 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants