pantherale0 / ha-fuelprices

A generic and extensible integration with pyfuelprices to retrieve local (or remote) fuel price data.
MIT License
19 stars 2 forks source link

Set a price as entity state #15

Closed Jab2870 closed 4 months ago

Jab2870 commented 6 months ago

Checklist

Is your feature request related to a problem? Please describe.

The home assistant map card allows for map marker text to display an entities state rather than an entities name. Currently, a map simply shows an abbreviation of a fuel station's name, which is not hugely helpful:

image

It would be much more helpful do display a fuel price, as demo'd here: https://www.home-assistant.io/blog/2023/10/04/release-202310/#map-entity-marker-options

Describe the solution you'd like

I would like the ability to set an entity's state to be the fuel price.

Describe alternatives you've considered

Could probably do it with template sensors, although that would mean having 2 entities for each fuel station - something I'd prefer to avoid.

Additional context

I suspect this would take the form of a selection during setup whereby a user selects the sort of fuel they would like to display as the entity's state. E10 or B7 for instance

Jab2870 commented 6 months ago

an additional advantage here is that the state is stored in HA history so the price of fuel can be tracked over time

pantherale0 commented 4 months ago

Will work on this for the next version, I agree, this would be much more helpful

pantherale0 commented 4 months ago

Small preview of what is to come. Need to write up some docs though first.

Home Assistant will actually capture the states into the long term statistics table in the backend so I found out a little while ago.

image image

pantherale0 commented 4 months ago

fixed in https://github.com/pantherale0/ha-fuelprices/commit/86e228227ed32eba439376134e9bc2d7836e75ae

Jab2870 commented 4 months ago

This looks great @pantherale0 . Thanks. have 2 queries:

  1. Is the data going to remain in attributes? I have a bunch of stuff that currently reads the data in attributes and I would have to re-write it if not. Not a huge deal, but would mean waiting to do the update until I have time to do them.
  2. What is shown if a particular station doesn't have the "chosen" fuel type. Lets say I pick E5 - which is normally called something like "Premium Unleaded" - would the state just be unavailable if a fuel station didn't sell premium unleaded?
pantherale0 commented 4 months ago

Hi,

  1. The data in the attributes hasn't changed apart from the addition of the area that generated the entity (#12)
  2. If the fuel station does not sell a specific fuel, the name of the fuel station will be used as the state instead (otherwise the attributes aren't available in HA as an entity always needs a valid state for those to show)
Jab2870 commented 4 months ago

So, downloaded the latest version and it's working great, thanks very much. 1 small thing is that the units are wrong. If you would prefer, I can open a new issue for it, but given it is a result of this I thought I'd ask here first.

image

This should be pence, not pounds.

pantherale0 commented 4 months ago

Discussed here, it's not a simple swap to pence as this integration supports other countries / currencies where the format varies.

https://github.com/pantherale0/ha-fuelprices/issues/13#issuecomment-2171913170

Jab2870 commented 4 months ago

Ok, no problem. thanks for the quick response