Is there a way to select what sensor i want to present in frontend?
So instead of a long list i want a input_select to chose the sensors i want to present.
Every selection should result in two values, distance and time.
just a rough brain storm, you could create an input select with your various options, and have an automation that hides / un-hides the appropriate entity based on which one is selected in the input select.
Do you have any example code of that?
Check here for input select, pretty self explanatory
Having a quick search, I may be wrong, but im not sure its possible to hide a single entity.
so the workaround would be create 1 group for each entity, and call the group.set_visibility
within an automation.
you could then hide the original entiutes via a customize glob perhaps, or individually within a customize.yaml
Yes i have input_select covered its the hiding part i really dont get
I would say a mix of (excuse the wording, extracted from my own automations)
- service: group.set_visibility
entity_id: group.xmas
data_template:
visible: >
{% if is_state("input_boolean.xmas", "on") %}True
{% else %}False
{% endif %}
and a for loop:
{% for state in states.sensor -%}
{%- if loop.first %}The {% elif loop.last %} and the {% else %}, the {% endif -%}
{{ state.name | lower }} is {{state.state_with_unit}}
{%- endfor %}.
Let me know if you need something a bit more defined…
Hopefully some of the more experienced gurus will correct me if im woring here, but I think youd need to define 1 group per each sensor you have. Check the docs on groups
You could then hide the original sensor:
customize:
sensor.whatever_time
hidden: true
sensor.more_whatevers
hidden: true
you could then use the automation to hide the appropriate group based on what is selected.
https://home-assistant.io/docs/automation/
untested but along the lines:
automation:
trigger:
platform: state
entity_id: input_select.commute
to: 'Bike'
action:
service: group.set_visibility
entity_id: group.xxxx
data:
visible: False
very barebones, but should give you a starting point.
It worked but got a little bit messy when the page reordered
if you’re still looking into this, here’s a for loop that will go through all your sensors, check if it’s got a destination_addresses attribute set (to only keep the google travel stuff) and if the entity name is the one of your dropdown menu, set it as visible, else hide it.
{% for state in states.sensor -%}
{% if state.attributes.destination_addresses is defined -%}
entity_id: sensor.{{state.name | lower | replace(" ","_")}}
visible: {% if state.name == states.input_select.name_of_your_dropdown_menu.state -%}true{% else %}false{% endif %}
{% endif %}
{%- endfor %}
I have to be honest i’ve never set such an action do not even sure if it’s possible. but I do like the idea od dynamic sensor display so do let me know if you manage to do it please
I came up with four groups and also four automations.
groups:
pendling:
name: 'Pendling'
icon: mdi:transit-transfer
view: true
entities:
- group.travel_gamlestan
- group.travel_hisingens_cykelklubb
- group.travel_molndal
- group.travel_vak
- input_select.commute
- group.anvandare
travel_gamlestan:
name: 'Buss och cykel Gamlestan'
icon: mdi:transit-transfer
view: false
entities:
- sensor.christer_till_gamlestan_buss
- sensor.google_travel_km_buss_gs
- sensor.christer_till_gamlestan_cykel
- sensor.google_travel_km_cykel_gs
- input_select.commute
automation:
- alias: 'Gamlestan'
trigger:
- platform: state
entity_id: input_select.commute
to: 'Gamlestan'
action:
- service: group.set_visibility
entity_id: group.travel_gamlestan
data:
visible: True
- service: group.set_visibility
entity_id: group.travel_vak, group.travel_molndal, group.travel_hisingens_cykelklubb
data:
visible: False
input_select:
commute:
name: 'Restider'
icon: mdi:transit-transfer
options:
- 'VAK'
- 'Bergfotsgatan'
- 'HCK'
- 'Gamlestan'
initial: 'Gamlestan'
Noticed that all groups was visible until i did a selection.
So i also added a automation that fires with reboot (startup)
- alias: 'Hass Startup'
trigger:
- platform: homeassistant
event: start
action:
- service: group.set_visibility
entity_id: group.travel_gamlestan
data:
visible: True
- service: group.set_visibility
entity_id: group.travel_vak, group.travel_molndal, group.travel_hisingens_cykelklubb
data:
visible: False