Brand new to HA and have some coding experience but really only in things like Javascript etc… VERY new to YAML…
I am trying to find a way to loop through a set of entities and retrieve the “message” attribute from them all… I have a small query that will find all the calendar entitie_id that I want. Each entity contains a message attribute. I was hoping I could somehow store the results of the first query in an array and use it to loop through each one and retrieve the attribute data… The issue is the result set is outputted as a string so if I try and loop the new variable it will just iterate each letter in a new line.
Create variable which is array of entity IDs from the first search.
create loop which will find the attribute from each entity and uses the array to loop through each entity
Use the output from each attribute and display on a card.
When I started this I was more ambitious, I wanted show the calendar events based on the user that was logged in. That proved very complex as there doesn’t seem to be a way to identify the person that is logged in so it makes it very hard to them look up the correct calendar and display that data. Instead I thought I would just pull all the calendar “message attributes” and show them all but even that is getting me stuck.
Templates based on the state object of a calendar entity can be unreliable if you have overlapping or all-day events. You will be better off using the calendar.list_events service call.
In HA, states are always strings. Attributes can be other data types.
You can use a State-Switch custom card to modify the card shown based on the active/logged in user.
Thanks so much for taking the time to reply. I will say this, I started this HA workas a means to push lots of my house IOT data into my Grafana and InfluxDB and play with lovely graphs but I have become totally hooked on HA as a program itself! It’s soo flexible but I guess that does mean it is quite complex…
Anyway… Thanks again for replying, I will spend some time to try and read through your suggestions…
The SS card looks good but looks like you have to set it manually. I was using a mushroom template card with
‘Hello {{user}}’ in the Primary Info and was hoping to use the secondary info to pull the next event from a certain users calendar. It seems to recognise ‘{{user}}’ in the card but not in the template.
Like this
The work around I have found is to share everything into a family calendar in Google (using the good integration) and then pull the data from one place. This just means everyone sees the same data rather then customised to their own calendar.
That should be do-able… as long as you keep a consistent naming method for the template sensors.
type: custom:mushroom-template-card
primary: Hello, {{user}}
secondary: |-
{% set ent = 'sensor.today_s_events_' + user %}
{% if states(ent) == '0' %}
No Events Left Today
{% else %}
{% set e = state_attr(ent, 'scheduled_events')%}
Next in your calendar you have: {{ e[0].summary}}- {{ (e[0].start|as_datetime).time()}}
{% endif %}
icon: mdi:home
The recently added Template sensor Helper is only capable of very basic template sensors, it does not currently support one’s that use actions or attributes. To use those you set up the sensor in your configuration.yaml file.
You replace it with the your calendar entities. If a user has more than one calendar you will need to combine them:
Any ideas why I might be getting some validation errors from the IDE? Looks correct from what I can see but I think there must be some issue as after a HA restart it doesn’t seem to have created the sensors.