nathan-gs / ha-map-card

A Map Card for Home Assistant
https://community.home-assistant.io/t/map-card-a-slightly-improved-map-card/693088
MIT License
15 stars 4 forks source link

FR: Set tile_layers options with template or from entity state #48

Open bezmi opened 1 month ago

bezmi commented 1 month ago

I am trying to use the Rain viewer API to render a rain radar overlay. The URL has a {time} field. Would it be possible to get the value for an option from a template or an entity (eg, input_number) and re-render the map smoothly when the value changes (eg, cycling over the last 5 snapshots)?

Currently testing this sort of thing with a custom:button-card to add the templating ability. It works, but the map is re-drawn every time the value changes, causing my location markers to pop out and then in as well.

nathan-gs commented 3 weeks ago

@bezmi take a look at v1.2.0, in #56 an alternative to this was implemented. Let us know if it does or doesn't fit your use case.

bezmi commented 1 week ago

The Rain viewer API expects the {time} field to be a plain unix timestamp (seconds since epoch). I believe the current implementation in #56 can only return a timestamp string as it uses HaMapUtilities.getEntityHistoryDate().

When querying the rainviewer API at https://api.rainviewer.com/public/weather-maps.json, the radar.past array contains the information to access the last 13 sets of tiles they've generated. I have restful sensor, sensor.rainviewer_tile_time, which uses the value of an input_select to get the timestamp of the N-th tileset from the api link above: radar.past.{input_select number}.time. Perhaps adding a convert boolean to history which enables/disables the timestamp conversion would be the easiest way to implement this?

type: custom:map-card
x: -27
'y': 152
zoom: 5
tile_layers:
  - url: https://tilecache.rainviewer.com/v2/radar/{time}/256/{z}/{x}/{y}/8/1_0.png
    history:
      property: time
      source: sensor.rainviewer_tile_time # unix timestamp
      convert: false # don't try to convert the value of `source` into a timestamp