#templates-archived
1 messages · Page 82 of 1
Ah, ok. Didn't realize that.
I expected it to work somewhat stream-ish.
On that subject, is there any such thing as a clamp functon that lets you restrict maximum and minimum values ?
in results of arithmatic expressions that is
yes that'll do.
{{ ([0, -10, 10]|sort)[1] }}
that clamps both min and max
middle value is the variable
That's a cool trick, gotta remember that...
@frozen galleon I converted your message into a file since it's above 15 lines :+1:
@frozen galleon you just place it in your configuration.yaml file, assuming you haven’t split it up
You’ll also have to change sensor entity names if they don’t match yours
Template shows a zero if number is lower as 10 but I want it to show 9 for example instead of 09. Anyone have a solution for this?
unique_id: "next_sunrise"
state: "{{ (as_timestamp(state_attr('sun.sun', 'next_rising')) - as_timestamp(now()))| timestamp_custom('Over %H uur') }}"
icon: mdi:weather-sunset-up```
Use %-H for a single 24 hour or %-I for single 12 hour
@edgy umbra When you just add the sensor.sun_next_rising sensor to your Dashboard, it will show exactly what you want, the relative time until the event
Yep i know but I want it on a custom button card (chip) and just shows the state (absolute time).
I have an automower, and its errro sensor shows nice human readable values when added to a dashboard, but other error ids when uses in a template. Is there a way to get that nice string instead of the error id?
You can use https://github.com/TheFes/relative-time-plus to also show minutes when it's less than an hour
Didn’t know this was available! 🙂
Hi, just received the Deprecated option used warning
Deprecated payload_template option used in MQTT publish action call to topic homeassistant/persistence/elian from payload template 2024-08-10 18:51:28.311808+03:00. Use the payload option instead. In automations templates are supported natively. Update the automation or script to use the payload option instead and restart Home Assistant to fix this issue.
Binary Sensor
http://pastie.org/p/1uNyruBa1o4IIsJSLDKJSF
Person Persistence.yaml
http://pastie.org/p/0xAxXCW3BC37CuctmOdvUy
Been trying to change manually but made a mess, need your help ❤️
Thanks!
Timestamps are driving me insane. I keep getting number sign hh:mm at the end, that I can't remove even with regex_replace.
{{ as_timestamp(states.sensor.blue_time_to_full_charge_2.state) | timestamp_local }} --> 2024-08-10T13:24:25-04:00 #13:24 #17:24:25
{{ as_timestamp(states.sensor.blue_time_to_full_charge_2.state) | timestamp_custom('%H:%M') }} --> 13:20 #2024-08-10T13:20:57-04:00 #13:20 #17:20:57
What is this junk?
{{ as_timestamp(states.sensor.blue_time_to_full_charge_2.state) | timestamp_custom('%H:%M') | regex_replace(find='#.*$', replace='') }} --> 13:04 #2024-08-10T13:04:31-04:00 #13:04 #17:04:31
I put a backslash before the # in the find, didn't help! Junk at the end shows up both in Developer Tools and on my dashboard.
{{ groups }}```
How to only get the groups with the "rgb_color" attribute in a template? I have this already: ^
{% set groups = integration_entities('group')| select('search', '^light.') | expand | selectattr("attributes.rgb_color", "defined") | list %}
{{ groups }}
I got thism, but only needs the entity_id, this returns a big ass blob
{% set groups = integration_entities('group')| select('search', '^light.') | expand | selectattr("attributes.rgb_color", "defined") | state_attr(entity_id, 'friendly_name') | list %} {{ groups }}
does not seem to work either; TypeError: state_attr() takes 3 positional arguments but 4 were given
map(attribute='entity_id') was the answer
how can one pull the actual time/date of an entity/device being last available (ie on/off , not unavailable) ? if i use last_changed it basically gives me the timestamp of when the last time HA was restarted
but to use either option means to create an entry in the config for every single entity (light) i have, which makes it hugely clunky. I see , for example in the history of one of my lights, the exact time it went from on to unavailable ... why can't i query that data?
or is there a way to stop whatever it is doing in terms of resetting the last changed time when it restarts HA? (is there a reason that it does?)
when you restart HA, the light entity goes from unavailable to a nominal state like on or off. That's a state change, so it will cause a last_changed to be updated
to find the last time it changed for on to off or vice versa you need ot either query the databse, or store them differently. If you look at the config for the template sensor, you will see you can use it for multiple entities, you don't have to create one for each entity
hmm ok, so querying the db which already exists is the logical option. I'll try to look up how to do that then (unless there any reasons why this would be a bad idea)
hmmm well it appears it is much easier said than done
I'm not an SQL expert, maybe someone in #integrations-archived can help with that
How can i get rid of the number after the dot?
float(0) * 1000 %}```
It now show 213.5 for example
You either truncate it by converting it into an integer or you round it
Surround it in parentheses and add |int or |round
is there a way I can make this work:
target:
entity_id: {{ states.light | selectattr('state', 'eq', 'on') | map(attribute='entity_id') }}```
Yes, by adding a list filter, and wrapping the template in quotes
perfect! that worked 🙂
what am I doing wrong here:
"{{ states.light | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | rejectattr('object_id', 'search','bathroom_') | rejectattr('object_id', 'search','guest_bathroom')|map(attribute='entity_id') | list }}"
also tried
"{{ states.light | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | rejectattr('entity_id', 'search', 'bathroom') | list }}
As soon as you do map(attribute='entity_id') you only have the entity_id's
No longer the full state objects
Do the rejects based on object_id before you map the attribute
entity_id: >
{{
states.light
| rejectattr('object_id', 'search','bathroom_|guest_bathroom')
| selectattr('state', 'eq', 'on')
| map(attribute='entity_id')
| list
}}
ah perfect thank you again
Good morning, I have received the Deprecated option used warning
Deprecated payload_template option used in MQTT publish action call to topic homeassistant/persistence/elian from payload template 2024-08-10 18:51:28.311808+03:00. Use the payload option instead. In automations templates are supported natively. Update the automation or script to use the payload option instead and restart Home Assistant to fix this issue.
Binary Sensor
http://pastie.org/p/1uNyruBa1o4IIsJSLDKJSF
Person Persistence.yaml
http://pastie.org/p/0xAxXCW3BC37CuctmOdvUy
How do I use the 'Payload' option as they say?
Thanks!
action:
service: mqtt.publish
data:
topic: >
homeassistant/persistence/{{ trigger.to_state.name | lower }}
payload: >
{{ now() }}
retain: true
so just removing the underscore template fix that?
I suspect so. The documentation has not been updated yet.
I gave the wrong data, and I cant delete this?
It's gone.
Ty
@steel swift I converted your message into a file since it's above 15 lines :+1:
@steel swift I got you covered https://github.com/TheFes/cheapest-energy-hours
Off course you have, impressed I am! Now I just have to figure out how this work. Going into your documentation now. I have Tibber, and as the grid prices are much higher between 06 and 22, I would have been nice if it is possible to find the cheapest hours between 22 and 06
Then use those as the parameters for start and end
Either use
start='22:00', end='06:00', include_tomorrow=true
Or
start=today_at('22:00'), end=today_at('06:00') + timedelta(days=1)
I dont think my head is working properly at the moment, think I have to read through all you documentation and try to understand this.
Can I send you a direct message?
I'm probably busy preparing a BBQ, you can create an issue on GitHub with your questions and then I'll respond later this evening
... it's the comments you're leaving in your template. You can't comment templates with # comment. You have to use jinja comments.
Thanks. I figured it had to be something dumb like that. I did eventually figure it out.
This is working great but one unforseen issue. The script this is feeding is expecting data formatted like this:
domain: pyscript
service: currency_convertor
service_data:
currencyfrom: us dollars
currencyto: euro
amount: '100'
but I am getting the value from the template you provided showing as:
amount: 100
What is the type that returns with quotes? Do I need to add some sort of convert to string?
The error I get when not quoted is:
Error: Failed to process the returned action response data, expected a dictionary, but got <class 'NoneType'>
You can add | string after join in the code but I don’t believe it will accomplish anything
It will get interpreted as a number anyway. In fact the code I suggested as-is should output a string without even sending it to the string filter
okay. So something else is going on though I can tell you that the service call succeeds just by adding the quotes. Weird
I’m not saying you’re wrong, I’m saying that there’s nothing you can do to a template to have it output 100 as a string instead of a number
Maybe you could put everything into a dict
action: pyscript.currency_convertor
data:
currencyfrom: us dollar
currencyto: euro
amount: "100"
This is how the service call formats when I run from dev tools. It is double quotes not single like I mentioned above if that matters. If I take them off I end up in same situation with the error about dictionary.
That's kind of what I'm doing with the above though right? That data: is a dictionary correct?
Yes
I am up for trying this but I don't know how to do what you are proposing
Yes, but I’m suggesting putting it in JSON form
Could I trouble you to educate me on how I might do that?
In your Python script, what is amount defined as? Are you using a type hint with it?
Yeah I was just thinking that maybe I need to change my python variable type to solve this. You guys may remember that I am not well versed in any of this stuff.
You can try this in your service call in dev tools to see if it even works
action: pyscript.currency_convertor
data: >
{{
{"currencyfrom": "us dollar",
"currencyto": "euro",
"amount": "100"}
}}
Ha! All good. We were all new once. Also, yeah, I’ve seen where pyscript gets weird with type hints and inbound service data.
Here's the definition section of pyscript service. Again, I got this to work and have done a few others but don't know excactly what's going on:
https://dpaste.org/8YPW1
This is what I get with the bit you shared:
This action requires field currencyfrom, which must be provided under 'data:'
is that with my updated edit, with the double curly braces?
If that doesn't work, I'm out of ideas
Yes, with the updated code. Okay. I'm stuck. This is so close but not sure why it won't store value as a string.
Just tried the pipe string you mentioned earlier and as you predicted it did not change things
Give me a sec.
That should work
it's complaining about currencyfrom
are you sure you're looking at the most up-to-date error @bronze prawn ?
You are talking about the attempt using @lucid thicket code above right? #templates-archived message
If so, I am trying to run from dev console services and that is the error it shows
You can't run templates through the service caller.
oh. Didn't know. Okay, let me add it to the automation....
Okay so that did run fine from within automation. I used as shown. Now the plan is to replace those hard values to the variables? Will I be able to get the one I am having trouble with to be quoted by using this method?
You should, yeah.
@bronze prawn I converted your message into a file since it's above 15 lines :+1:
grr.. I tried to keep it under 15
That will show it better. So I tried switching the hard values for the variables but I am still getting errors. It is not setting the fromamount value with quotes so it is again failing
Is the error I'm getting coming from HA or from the pyscript script?
No way to force quotes around this value? It will always be evaluated as a number?
will a float be converted the same way?
why are you doing it in variables?
that forces HA to resolve the template type
just put those templates in data's output
ohhhhhhh.. I'll try that.
action: pyscript.currency_convertor
data:
currencyfrom: "{{ trigger.slots.fromcurrency | reject('in', '0123456789') | join | trim}}"
currencyto: "{{ trigger.slots.tocurrency }}"
amount: "{{ trigger.slots.fromcurrency | select('in', '0123456789') | join }}"
response_variable: conversion_response
enabled: true
Like this? If so, it evaluates the same as with variables and amount is not quoted which is causing the same error
okay. I'll give that a go. Thanks for the patience
action: pyscript.currency_convertor
data: |
{{
{"currencyfrom": trigger.slots.fromcurrency | reject('in', '0123456789') | join | trim,
"currencyto": trigger.slots.tocurrency,
"amount": trigger.slots.fromcurrency | select('in', '0123456789') | join }
}}
response_variable: conversion_response
enabled: true
This worked! Thank you all for the help!!
Only one other thing. I would like to have a check on the amount that if the user does not set a value then return one? Is that something easily added?
You’ll want to do that in your pyscript.
Hmm okay. I will have to look into how to make some variables not required I guess. Then if the value is not passed then set to one within that script. Got it
Thanks much.
Hey all, is there a template-ish way to get at the options available for a select.something entity?
{{ state_attr("select.air_purifier_countdown", "options") }}
so if we amend that by [1] we would get the first option, right?
That will get the second option
🤦♂️ If I mix up zero-footed and one-footed lists, it's probably time to call it a day...
There’s also a action that will get the first or last option as well without having to use a template at all.
Oh the way things are going, I'll have to write a script again anyways.
select_next might prove useful though.
Anyways, I think I've overdone it a bit. I'm deathly tired, have enough heartburn to heat a jacuzzi and am nowhere near finished with my chores for today...
Yup. Time to step away and do other things. 🙂
Like chores you mean...
I was gonna say touch grass… But… lol
I promised my mom I'd never do that 😉
I'm ever so slightly worried about my new ball turret camera...
two windows show two entirely different views, both with the time counter happily ticking away...
can i style text in a template like italic bold etc? im using mushroom template card.
No. You can use a Markdown card or maybe a tile card.
Is there a nice trick to cause a helper template to update every N duration that's not updating by itself? I'm using a template that just filters on integration_entities
Maybe the homeassistant.update_entity action in an automation 🤔
Yeah. I was hoping to do it in the template. I think I could just call a time function but then it just updates every minute right?
A little surprising that function doesn't cause template updates since I'm pretty sure there are events you can listen for
I have a mushroom-select-card on a frontend dashboard, and I would like to use a template for the 'entity' attribute (so I can have the card use the appropriate input_select based on the users username).
Is this possible?
Thanks!
you can just put now() in your template and it will render every minute
Yeah I know
I guess I could make an entity that updates at some interval and then add a state listener for that lol
I think the automation seems like a better option at that point though
sounds like you need a trigger-based template sensor instead of a state-based one
Well maybe, but I was just wondering if there was a way to do it with a template
@atomic blade integration_entities() itself doesn't set listeners for the entities involved, but if you apply certain filters on the result it will set listeners. So you could for example use expand
or states
Ah cool that's the sort of creative idea I was looking for 🙂 I think in my particular case it wouldn't work because I'm looking for listeners on when new entities are added and I believe this would just listen for change events on existing entities?
depends on how frequent those states change
it will run the full template on each state change of those listed entities, in case there are new entities it will add new listeners
But unless there was a state change on an existing entity, wouldn't the template not even evaluate for there to be new entities on which it listens?
Should have posted this originally but here's the template
{{
integration_entities('iBeacon Tracker')
|map('device_id')
|unique|list|count
}}
That integration spontaneously adds new devices so I have to occasionally go in and delete ones I don't care about before it grows to 200+ lol
it won't add listeners for the new entities until it is aware that they exist (and that is when it evaluated again after a state change of any of the old entiites)
but this template itself doesn't add any listeners, so it's basically static until the next time template sensors are reloaded
Yeah exactly. I've just created an automation that updates it about every day
Only way templates register entities for listening is if you access the state object.
why not create a trigger based template sensor then?
which you aren't doing
Yeah could do that too. I've been trying to keep things in the UI when I can
huh
{{
integration_entities('iBeacon Tracker')
| expand
| map(attribute='entity_id')
| list
}}
this only returns 2 entities
{{ integration_entities('iBeacon Tracker') }}
This returns 38
async_track_state_added_domain seems like the closest thing I'd be looking for from looking at the docs
shouldn't be the same list?
Disabled probably
That's what most of mine are
Like if a car drives by and it's never seen again, the device gets added and then disabled after some period of time since it's not seen again. Pretty sure that's how it works?
template entities do not do that
Although actually that doesn't sound completely right.
they only listen to state change events
ah right, integration_entities() shows disabled entities
Ah ok. Wasn't sure if they ever listen to other kinds of events
async_track_state_added_domain anyways wouldn't be exactly what I'm looking for since I'd have to listen to all sensor registrations
nope, only state change events. A new system would need to be added for other events
IMO we need to add them anyways for things like forecast, events, & todo's
That explains why there's no listener there then
todo's don't have a state?
Looks like it's some count
That's going to probably limit you though since it doesn't track a lot of the more minor changes that aren't kept in the state?
It's been a long time since writing a template - I'm sure I'm doing something silly wrong but I can not for the life of me figure it out. Could anybody provide some guidance please?
https://dpaste.org/hizyX
what's the output of {{ states('sensor.varberg_c_0') }} in the template editor?
16:03
{% set t = states('sensor.varberg_c_0') | today_at %}
{{ (t - now()).total_seconds() / 60 }}
well, if you're assuming it can be in the past...
{% set s = states('sensor.varberg_c_0') | today_at %}
{% set t = now() %}
{% if s < t %}
{% set s = s + timedelta(days=1) %}
{% endif %}
{{ (s - t).total_seconds() / 60 }}
@opaque sentinel ^
Awesome, way simpler as well. Thanks!
TemplateError('ValueError: could not convert str to datetime: 'Unavailable'') while processing template 😵💫
Guess I need to convert the state to an int somewhere?
No, you need to add an availability to it
are you making this in the UI or via yaml?
it can't if you need availability
availability_template: "{{ 'sensor.varberg_c_0' | has_value }}"
put it above value_template, indented at the same level with it.
you can let a GUI created template with a unit of measurement retrun none as an alternative for availability. That will make the state unknown
Thanks, it works!
Now I get a warning The entity definition format under template: differs from the platform configuration format. See https://www.home-assistant.io/integrations/template#configuration-for-trigger-based-template-sensors
Just out of curiosity, do I read the docs right that value_template: should be replaced by state: nowadays?
If you use the old format, you must use the old keys.
if you use the new format, you must use the new keys.
you cannot mix and match old and new formats
hi quick question does this
- platform: time_pattern
hours: /1```
update a template at every new houre like 17:00 18:00 19:00 or does it updata one houre later then homeassistant is started?
so if homeassistant is started at 16:34 it updates at 17:34
it does on-the-hour
ah so it doesn't depend on homeassistant boot time
it used to, way back in the day
alr thx that clears it up
btw i would like for the data in the template to be more accurate so i was thinking instead of running it every houre chaning it to run every 5 minutes will this affect preformance or slow homeassistant down or is this prefectly fine?
getting data from my weather entity for the next 6 houres
probably fine
only concern would be if it causes you to hit api limits
depending on the weather service you use
does calling the service Weather: Get forecasts call the api or does it just get the data that was already in homeassistant?
because if it does i will probably have to increase the trigger interval
it depends on the integration
im using openweather
🤷♂️ without looking at the code, I can't tell you if it does or doesn't
i think it doesn't because my api usage is the same as yesterday and i have been calling the service all day so it's probably fine
and i have limited my usage to 1000 call wich is the daily limit so if i it does it will not charge me
but thank you for the help
mhm i will keep an eye on the api usage for now
Does the UI support editing a template sensor with trigger?
Nope
@lapis hound I converted your message into a file since it's above 15 lines :+1:
@lapis hound I converted your message into a file since it's above 15 lines :+1:
The error I am getting is this: Invalid config for 'template' from integration 'sensor' at sensor.yaml, line 137: expected SensorDeviceClass or one of 'date', 'enum', 'timestamp', 'apparent_power', 'aqi', 'atmospheric_pressure', 'battery', 'carbon_monoxide', 'carbon_dioxide', 'conductivity', 'current', 'data_rate', 'data_size', 'distance', 'duration', 'energy', 'energy_storage', 'frequency', 'gas', 'humidity', 'illuminance', 'irradiance', 'moisture', 'monetary', 'nitrogen_dioxide', 'nitrogen_monoxide', 'nitrous_oxide', 'ozone', 'ph', 'pm1', 'pm10', 'pm25', 'power_factor', 'power', 'precipitation', 'precipitation_intensity', 'pressure', 'reactive_power', 'signal_strength', 'sound_pressure', 'speed', 'sulphur_dioxide', 'temperature', 'volatile_organic_compounds', 'volatile_organic_compounds_parts', 'voltage', 'volume', 'volume_storage', 'volume_flow_rate', 'water', 'weight', 'wind_speed' for dictionary value 'sensors->lights_on_count->device_class', got 'light' Invalid config for 'template' from integration 'sensor' at sensor.yaml, line 138: 'state' is an invalid option for 'sensor.template', check: sensors->lights_on_count->state
well, you are provding an inoccorrect device_class. Remove the line wiht device_class: light
@lapis hound I converted your message into a file since it's above 15 lines :+1:
Please see above
Which says state is invalid. What do I need to put there instead?
Is it supposed to be available and unavailable?
state is not valid for the legacy format you are using
value_template determines the state
- platform: template
sensors:
lights_on_count:
friendly_name: "Lights On Count"
value_template: >
{% set lights_on = states.light
| rejectattr('entity_id', 'in', ['light.upstairs', 'light.russell_s_bedroom'])
| selectattr('state', 'eq', 'on')
| list
| length
%}
{{ 'off' if lights_on == 0 else 'on' }}
icon_template: >
{{ 'mdi:lightbulb-off' if this.state == 'off' else 'mdi:lightbulb-on' }}
btw, I would advice to use a binary sensor here instead of a (normal) sensor. They only have the state on or off just like you want it to have
and I would advice to move to the modern template (binary) sensor format
I still want to be able to display the number of lights. I am trying to use the new badges.
@lapis hound I converted your message into a file since it's above 15 lines :+1:
Ok, I have converted it and it still won't do what I am trying to do. I just want the icon to light up when the count is greater than 1 and be grey when the count is 0 while still displaying the number
No, you are now mixing old and new format
The new format is under the template integration instead of the sensor integration. You can't place it in sensor.yaml
Thank you for all your help. I actually believed that I made a binary sensor, realized I did not. And yes the intension is that the automation shall trigger only 1 time per hour. Anyway again thank you, this saved me a lot of work.
I have a sensor that is increasing and decreasing (fluid). How can I just count the decresing values? I would like to know how much (Liter) is going out.
You could make a template sensor that just makes the sensor negative e.g. {{ states('sensor.fluid') | float * -1 }} , and then feed that into a utility meter helper with “net consumption” disabled.
Alternatively you can create a trigger-based template sensor in yaml with the appropriate logic, if you don’t like the idea of two separate entities.
this would work, need to be in yaml. You have to count both increasing and decreasing values. https://dpaste.org/uJnQg#L22
there's probably an error in there. {{ this.state | default(0) | float + decrease }}
Hey there
looks like im at right place here 🙂
How should i best set up some AND as well as OR conditions?
like if any heating valve (command value i think is the correct signal) goes above 0, i like to set a helper to true which will turn on the pump
if ALL heating valves are 0, the helper should be false and pump should go off
I got a hint that a template helper could be what i need to create
that's just an automation and normal conditions that you can build with the UI
and & or are normal conditions you can select
I pointed him here as what he really wants is a group of sensors that are above zero to trigger an input_boolean.
I figured a template binary sensor would be a good solution for that.
What he wants is if [any sensor in sensors] > 0, toggle an input_boolean.
That's still probably doable without templates
sensor group with type set to maximum. Then use that as a trigger above 0
Oooohhh yeah, that could work too.
Hey, im using this command to split "Restabfall in 2 tagen" to "Restabfall" only, now i need to check "Restabfall morgen" too, how i can splitt this in following command too? i think it exists an little bit better way to 🙂
{{ states(entity)[states(entity).find("in "):] }}
Restabfall in 1 tag > Restabfall
Restabfall in 2 tagen > Restabfall
Restabfall morgen > Restabfall
Like this?
{{ 'foo bar'.split()|first }} -> foo
like that i found currently
{{ states("sensor.nachste_abholung").split(" ")[0] }}
I'm very confused why your original template is so complicated
If you just want the first word, then use .split(" ") like you've just came up with
because im no programmer and it was try and error
whit them i play currently to find if its working 🙂
works with {{ states("sensor.gelber_sack").split("in ")[0] }} & in {{ states("sensor.gelber_sack").split("in ")[1] }} - Thanksfor the tipps
is it possible to split in "Morgen" too in this strings?
the value can be "morgen" or "in x tagen"
hi @willow wing . What do you want to do ? Looks like it is related to "Waste collect " .... is it coming from a calendar or ...?
i have a value with "Restabfall morgen" or "Restabfall in x Tagen" now i need 1 string that splits to the front "Restabfall" for a label, and a split for the day like morgen or in x days as the state, it comes from waste scheduler integration
the split with "{{ states("sensor.gelber_sack").split("in ")[0] }}" works when the values is restabfall in x days, but not with morgen
just split on " " not on "in "
just like petro already showed in his example, or don't use any paramter like Rob did in his example
" " does not work for "in x days" it does work only for the label when i need [0]
{% set str_source = "my string to split" %}
{% set first_word = str_source.split(" ")[0] %}
{% set end_string = str_source.split(first_word)[1] %}
{{ first_word }} - {{ end_string }}
``` => `my - string to split`
So what do you want as result?
input: Restabfall in x Tagen > output: ??
input: Restabfall Morgen > output: ??
{{ states("sensor.nachste_abholung").split(" ")[0] }} -> Restabfall
{{ states("sensor.nachste_abholung").split(" ")[1] }} -> Morgen -> but sometimes the name in "in x days" so the output is only "in" with [1]
nope the same results
Please answer my question
It is not clear what you want as output
if the state of your sensor is Restabfall in x Tagen, what do you want to have as result
if the state of your sensor is Restabfall Morgen what do you want to have as result
hä, again, this value has 2 states "morgen and in x tagen" and i need a split 1 for before the text like [0] (Restabfall) and one after the text (Restabfall) of [0]
1 string with restabfall and 1 with "in x tagen"
1 with restabfall and one with morgen
{{ states("sensor.nachste_abholung").split(" ")[0] }} will give Restabfall
{{ states("sensor.nachste_abholung").split(" ")[1:] | join(' ') }} will give the other thing you want
Restabfall is possible with that string "{{ states("sensor.nachste_abholung").split(" ")[0] }}"
the problem is the second one with the both values
this looks good, but the value sack is in the output
value sack?
Sack in x Tagen is the output, but should be only "in x Tagen"
of cource, we print both ! 😉
You never mentioned Sack before. You said the state was Restabfall in x Tagen
So what is the actual state of that sensor
oh your right sorry, gelber sack is a other vlaue that it can be - Gelber Sack, Restabfall, Papiertonne and Hackgut
sorry my misstake
ROFL 😉
so in that case you want it to be Gelber Sack and in 2 Tagen?
=> So a table of "keywords" to split the line , and the "end of line" ? I'ts becoming funny 😉
this values are possible
Restabfall in x Days
Restabfall Morgen
Gelber Sack in x days
Gelber Sack Morgen
Papiertonne in x days
Papiertonne Morgen
Hackgut in x days
Hackgut Morgen
{{ states("sensor.nachste_abholung").split(" ")[:2] | reject('in', ['in', 'Morgen']) | join(" ") }}
{{ states("sensor.nachste_abholung").split(" ")[1:] | reject('eq', 'Sack') | join(' ') }}
we need to remove only the first words i think (dont know if this is possible), the first one we have already with {{ states("sensor.nachste_abholung").split(" ")[0] }}
Gelber Sack is 2 words, that makes it a bit more complicated
That will only give Gelber instead of Gelber Sack
yeah that looks perfect, thank you guys, sorry for the missing info about the extra vlaues.
{{ states("sensor.nachste_abholung").split(" ")[:2] | reject('in', ['in', 'Morgen']) | join(" ") }}
{{ states("sensor.nachste_abholung").split(" ")[1:] | reject('eq', 'Sack') | join(' ') }}
again, that first one will return Gelber, not Gelber Sack
{{ states("sensor.gelber_sack").split(" ")[1:] | reject('eq', 'Sack') | join(' ') }} this gives in tempalte edior the right text "in x tagen"
aaah yeah your right
I'm not talking about that one
Maybe you have enough to experiment on your own?
@gilded raven I converted your message into a file since it's above 15 lines :+1:
https://i.imgur.com/BMzFFHW.png - this is the UI i'm looking at
what if it's none of those?
then off I suppose
then:
{{ states('sensor.whatever') in ['On', 'Buffering', 'Playing'] }}
so {{ states('media_player.playstation_4') in ['On', 'Buffering', 'Playing'] }}
you missed a ]
edited
yes
those aren't the correct states
those are translated states
you need the untranslated ones from developer tools -> states page
yeah, you need to review
-> States for what they actually are
https://i.imgur.com/yKPMyWL.png - it doesn't give me a list and I'm out right now
you'll need to find out
experimentation
searching the forum or here, maybe somebody has done that work
maybe it's just what you gave, but lowercase
You cannot easily look at the raw state history, and the state will be translated in the UI in most places
and what would be the correct device class for this?
power looks wrong as it's labeled 'Clear' when off
this is best done when you're in front of the thing, rather than while you're away
does the frontend translate it or the backend, because i'm familiar with devtools etc
frontend
so network tab could help me
not sure what "network" tab is
in devtools
there is no network tab
Yaml, states, actions, template, events, statistics, assist
not HA devtools, chrome devtools
anyway yeah i'll have to do it when i get home then
yes, potentially
it's all the same but lower case
yeah it looks like power device class isn't right at all?
It's giving me the options: Detected, Clear, Unavailable, Unknown
if you just want on/off in the ui, choose nothing
power will give you on/off, motion is detected/clear
is it not updating then?
clear your cache & try again
do you mean browser cache?
Yes
just went on a different browser entirely and it still says clear/detected
100%
remove the device_class then
doesn't let me
click the x
I did. Upon saving, then going back into it, it's back to being power
this is a UI created template entity?
correct
did you click submit after clicking x?
yes
🤷♂️ working for me
delete that and create a new one, don't specify the device_class
Any idea how I can make a template sensor to calculate the difference between the current sensor value and the last value?
e.g. if it said €13 yesterday then €14 today I want a 2nd sensor to show "+€1" ??
I have a template that uses now() which means it should be updated every minute under the hood, right?
but it doesn't seem to be
if I copy the template to the developer tool template editor and use it, it gives the correct value
but if i just import and the original, it's like it's an hour behind
yes, it will.
Post your template, what you're saying doesn't make sense
keep in mind, if the state is the same, it will appear as if it wasn't recalculated.
I agree that it doesn't make sense
template contains now()
should return 0 now, and did when pasting it in the template editor
but when importing it instead and calling it, it returned 50
that makes me think the origisnl hadn't been re-rendered for an hour or something even though it should have
a reboot fixed it.. for now at least
can you just post the template?
there's no way the minutely rendering is failing
there's likely an issue in your template
why wasn't it failing when I pasted the entire thing into the template editor then
there are many reasons it can fail, I can't tell you without seeing the template
I don't know why you are unwilling to share the template
startup or reloading typically breaks templates if the user does not add safety into it. And most users don't know how to do that.
and it 100% depends on what functions, filters, or tests you are using in the template, so there's no "here's the answer" without looking at the template.
just took a while to download from my phone
@gritty ledge I converted your message into a file since it's above 15 lines :+1:
{% endif %}
{% endfor %}
{% endmacro %}
``
That should calc fine through restarts, though you are overwriting now which you shouldn't do
also, today_at registers templates for minutely updates
generally works fine but sometimes it seems to get stuck
restart fixes it when it happens
Well, you don’t have an else clause. So what happens when it returns nothing?
Typically HA will remove listeners as it’s now unavailable
Also, check your log for errors. If you hit a divide by zero error, the template will also remove listeners
do trigger time templates get excluded from long term statistics even if they are type measurement?
I have a template that I was getting long term statistics for, and ever since I moved it to a trigger time (so it only updates once daily) there have been no more updates to the long term statistics DB
- trigger:
- platform: time
at: "23:59:00"
sensor:
- name: "Daily Driving"
unit_of_measurement: "min"
device_class: duration
state_class: measurement
unique_id: sensor.driving_stats
state: >
{{ (states('sensor.driving_since_midnight') | float * 60) | round(0) }}
this is the sensor in template.yaml, to be specific
Sorry for late response. How exactly would you do it? I usually do my automations as follows and i think its wrong 😄 But the german translation did maybe also mislead me
I put the actual logic as trigger (when), i do not use conditions (in german it says "only if" which i dont need if i already have the "if" - but this "if" is actually just the trigger).
If i put all sensors as trigger (when) and then select "command value" and "Above Mode = Fixed Number" plus "Above 0" ... it triggers always, even if there is no command value above 0
and are there maybe somewhere somehow options to just do automation by text? with like IF THEN ELSE conditions instead of using UI? Maybe i can handle that better - at least if some AI will tell me commands 😄
This is still relating to any of your heaters (TRVs?) being above 0 and then toggling a helper, right?
yes
i like to switch on the pump if any valve needs to turn on (OR logic above 0). pump should switch off if no valve need to turn on (AND equal 0)
thats apparently the command value of the heating-object (knx)
(command value state address)
Ok, so in the UI, go to Settings > Devices & Services > Helpers and create a new helper of type "Group" and then "Sensor group". In there, set your members to be the sensors you want to track and the Type to be "Maximum". That will give you a new sensor entity that will be > 0 if any of the knx sensors are above 0.
that sounds pretty easy
It is 🙂
🙈
Then, that new entity (name it something meaningful when you create the group, obvs) will be your trigger entity in your automation.
trigger:
- platform: numeric_state
entity_id: sensor.[whatever_you_named_the_group_entity]
above: 0
id: above
- platform: numeric_state
entity_id: sensor.[whatever_you_named_the_group_entity]
below: 1
id: below
ok i think ill have to figure out what the heating entities are... it doesnt appear under members when choosing sensor group
Interesting... yeah, figure out which domain they are in (maybe they are number entities?) If that's the case, it changes it a bit and we can account for that with a template sensor.
its a "climate" thing
Oh! They're climate entites?
its like this in knx.yaml
climate:
- name: "FBH EG ELW Wohnzimmer"
temperature_address: "x/x/x"
command_value_state_address: "x/x/x"
target_temperature_address: "x/x/x"
target_temperature_state_address: "x/x/x"
operation_mode_address: "x/x/x"
operation_mode_state_address: "x/x/x"
Ok. Those are climate entites then.
Well, they can (using old style groups). But, you really only care about the temps on them for this, right?
i care only about the "command_value_state"
that signals the position of the valve
if its 0, valve is closed
if its 100, valve is fully open
Ok and that's an attribute?
i think thats how its called
i have to change UI to like enable the card to show it
default heating card does only show current and setpoint as well as HVAC mode
If you go to developer tools>states and look at the device, what does it show? Use imgur.com to show me a screen shot of it.
oh yes, its attribute "command_value"
Ok.
well that page is nice
So, slightly different approach here. How many of them do you have?
19 or 20 around
And they are your only climate devices?
yes i did only set up some in knx.yaml
everything else is like a mitsubishi AC unit but that comes by integration, not by knx.yaml
Ok, in developer tools>template, enter in the following and tell me what you get: {{ states.climate | map(attribute="entity_id") | list }} (Sorry, use this one)
ive got some more apparently 😄
but the ones we need all begin with "fbh_"
like this climate.fbh_eg_elw_wohnzimmer
Ok. Give me a sec and I'll have something for you.
I live up to my name 🤣
😄
maybe OT: Is there any place / method / option ... where its possible to use something like javascript or any language that i can refer to and just put text logic? or is everything sort of special HA coding language?
i think NodeRed yes but beside that?
i feel sort of that templates is what i mean 😄
No. Well, yes, but no. The froontend can do JS, but for anything in the backend, it's all python and jinja.
Hi all, I'm looking for some help with templating. I'm trying to create a motion class binary sensor from the event triggers of my Google Nest doorbell. I tried following the one post on the forums. But it doesn't work. Here is what I have:
template:
trigger:
- platform: device
device_id: 2e71e33a4ffb1b448df53adc3f55fe39 # Nest Doorbell
domain: nest
type: camera_motion
binary_sensor:
- name: "Doorbell_Motion_YAML"
device_class: motion
auto_off: 0:00:10
state: on
- we can't help because it's not formatted. 2. are you pasting all of that into the UI? If yes, you can't do that. You have to put that in configuration.yaml.
I copy and pasted it directly from my configuration.yaml
template:
trigger:
- platform: device
device_id: 2e71e33a4ffb1b448df53adc3f55fe39 # Nest Doorbell
domain: nest
type: camera_motion
binary_sensor:
- name: "Doorbell_Motion_YAML"
device_class: motion
auto_off: 0:00:10
state: on
I don't know why its adding that extra line after trigger and formatting the hyphens (-) like they are bullets
trigger:
- platform: device
device_id: 2e71e33a4ffb1b448df53adc3f55fe39 # Nest Doorbell
domain: nest
type: camera_motion
binary_sensor:
- name: "Doorbell_Motion_YAML"
device_class: motion
auto_off: 0:00:10
state: on```
there we go
KNX help
I was using block quote instead of code block. that's what you get for reading the markdown page too fast
trigger:
- platform: device
device_id: 2e71e33a4ffb1b448df53adc3f55fe39 # Nest Doorbell
domain: nest
type: camera_motion
binary_sensor:
- name: "Doorbell_Motion_YAML"
device_class: motion
auto_off: 0:00:10
state: on```
Pasted directly from my Configuration.yaml file
What exactly doesn't work? It doesn't turn on? It doesn't turn off? It never changed from unknown?
And please edit your incorrectly formatted post next time and change the formatting there, instead of posting the same thing 4 times
It's not changing from unknown
are you 100% sure that trigger works?
OMG, so based on the post I was following it wasn't clear which way to set the state.
I had used `state: "{{ trigger.json.motion }}"
But just now before I posted i used > state: on
now it works
Now I feel like all the people that put in a HelpDesk ticket saying " I don't get it. It started working as soon as you showed up!"
@jaunty wyvern I converted your message into a file since it's above 15 lines :+1:
Please stop double posting, we can see your initial post.
template:
- trigger:
- platform: time
at: 00:00:00
- platform: homeassistant
event: start
sensor:
- name: Day
state: "{{ now().strftime("%A") }}"
- name: Month
state: "{{ now().strftime("%b") }}"
- name: Month Day
state: "{{ now().strftime("%A, %b") }}"
Hello, I can for some reason not get the different include methods into my thick skull. How do I properly include these files as simple as possible? The view part of this file works, but not the button card templates: https://i.imgur.com/sm4Yb9f.png
#frontend-archived please
This channel is specific to Jinja templates, not anything that includes the word "template"
and if you hop over, please dont post screenshots, but properly formatted yaml
Figured this was the best way to include the directories, but in hindsight maybe not.
This is what I'm to replace with my sensor ?
Petro gave you the whole code
Hi, I'm trying to make a binary sensor that will report true when the temperature outside is colder than the temperature inside. ie: temp_outside < temp_inside this is my current template, but it's always evaluating as false no matter what I do. I've flipped the < to a > and even used developer tools to view outputs and it outputs the correct numbers for the values of the temperatures and the correct true/false for the </> comparison:
template:
- binary_sensor:
- name: Open windows
state: "{{ state_attr('weather.tomorrow_io_home_daily', 'temperature') | float < states('sensor.t6_pro_z_wave_programmable_thermostat_air_temperature') | float }}"
any help would be appreciated
try {{ (state_attr('weather.tomorrow_io_home_daily', 'temperature') | float(0)) < (states('sensor.t6_pro_z_wave_programmable_thermostat_air_temperature') | float(0)) }}. I'm not sure why they would render properly in the template editor but not in the sensor def.
same thing, still reporting as false no matter which way I flip the comparison
Oh wait... did you create the weather sensor using the get_forecasts() action call?
i don't believe so, only because i haven't seen that before. unless it's done automatically for me.
I used the tomorrow.io weather integeration to get the weather, then the temp attribute to get the current temp outside
@flat gulch I converted your message into a file since it's above 15 lines :+1:
Huh weird... So, what about trying to create the sensor through the UI?
Settings > Devices & Services > Helpers > Add > Template > Template a binary sensor and adding your jinja there?
that's how i initially created it, but let me delete it and try again
same thing. in the preview, says closed both ways
aka false. i made the device class windows, so it reports as open/closed
That's really weird! Let me test it here.
interestingly enough, i tried this temp_inside < 4 and temp_inside > 4 both report false
just shortened it for the message, but used the correct jinja templating format to get the values
Here it works as intended: https://imgur.com/a/gzsVnyw
I inverted the < to > to make it true, but yeah... I'm not sure what's going on with yours tbh.
i am stupid basically lol

i was putting the whole yml and not the just the state yml
i saw the warning above the state template, but the documentation always had the template: -binary_sensor thing, so i always included it...
Doesn't it warm against that now, or are you but on 2024.8 yet?
it does warn, but i admittedly skimmed the documentation and only saw the full yml, and misunderstood the warning
thank you very much for the help @code
That's all under the YAML configuration header
But only skimming it will make you miss that 🙂
Yeah, it does warn against it now in 2024.8.
Happy to help!
this was my first time messing with the templates, so all user error, part of the learning lol
i'm just glad you tried it out and sent that screenshot... immediately had the duh moment
Eh, no worries... people here can attest to some of my, um, stupider moments...
-# that I still have
How do I create a template sensor with a device_class=timestamp? I tried ```template:
- sensor:
- name: Now
device_class: timestamp
state: "{{ now().timestamp() }}"``` but doesn't seem to work
- name: Now
Oh nvm, figured it out --- need to drop the timestamp()
@kindred garden I converted your message into a file since it's above 15 lines :+1:
Any help would be mega appreciated :)
@kindred garden I converted your message into a file since it's above 15 lines :+1:
This one is what I have so far, apologies ^
You can’t use a # to create a comment in the middle of a template
Yeah I realised that and removed it
but I'm still experiencing the same issue with the icon not appearing
What do you get if you paste that template into the template editor in developer tools
@kindred garden I converted your message into a file since it's above 15 lines :+1:
The template is just the stuff with curly brackets. The rest is YAML which the template editor doesn’t do anything with
I’m not a frontend guy but are you sure this card even takes templates in this format? Looks like the documentation shows JavaScript formatted templates (square brackets and such).
You’ll want to ask over in #frontend-archived for help on this one
Thank you, I'll give that a go.
Someone know how to get the latest response from this conversation.llm_model_fixt_home_3b_v3_latest_remote can't figure it out. I've tried {{ state_attr('conversation.llm_model_fixt_home_3b_v3_latest_remote', 'response') }} {{ state_attr('conversation.conversation_result', 'response') }} and {{ response.speech.plain.speech }} also {{ conversation.llm_model_fixt_home_3b_v3_latest_remote.response.speech.plain.speech }}
the response is not an attribute of the conversation entity, you need to run the service call with the prompt in your automation/script and then use the response variable
Ok, so if I have response_variable: testing How to get the response?
{{ testing.response.speech.plain.speech }}
Now I think I got it. Thanks
How do I grab certain attribute data to show in my notify.lgtv automation? this data can be multiple times with different values inside them.
https://imgur.com/OEBZlOR - Here on the attribute list under the first data it's the city name that getting bombed as I'm writing this message.
the cities below it happened before so it's like showing the history of bombs in the current day.
My question is how do I grab only the cities names and put it as a message to the LG TV? (trigger will be when state changes to on)
Sample of when there were no bombs in the last 10 minutes so state changes to off and under country_active_alerts there's nothing.
https://imgur.com/I2YhTge
What's the city name? Is that what's after title?
Also, please don't use images to share text
Yeah sorry, had to capture it quick before the 10 minutes were over.
I shoul've just copy the text.
Yes, on data field. but keep in mind there can be multiple missiles at the same time so there will be many cities (data).
I guess it has something to do with
{{country_active_alerts[0].data}}
For example today they bombed us 8 times at the same time on different cities, it looks like that on the attributes
http://pastie.org/p/0NyV1ELWPnKPZ1nArKez6q
This would give you a list of all the unique cities:
{{ state_attr('binary_sensor.oref_alert_all_areas', 'country_alerts') | map(attribute='data') | unique | list }}
fighting a bit with auto-entities, for a fellow user to get the ungrouped lights in his system, I wondered of we couldnt template those more easily, than listing all light groups manually and excluding those...a jinja template to do that isnt as straighforward as I had hoped though.
it would need a list for all lights (easy) and then reject all individual lights in all light groups (struggling a bit there)
the latter would have to work with the expanded lights in this {{integration_entities('group')|select('search','light')|list}}
yes, that one is easy 😉 this is the other way around, which seems less obvious. need to iterate over all of these light groups and select their entity_id's in a list to be able to reject an entity_id in them
Just expand all the groups to get all the members
{% set groups = integration_entities('group')
| select('match', 'light.')
| list
%}
{% set members = groups
| expand
| map(attribute='entity_id')
| list
%}
{{ states.light
| map(attribute='entity_id')
| reject('in', groups + members)
| list
}}
thanks!
that would do it indeed... let me try that in auto-entities. I might have to add a few other groups, ads not all grouped lights can be caught in the group integration but are eg hue_groups. these can be easily added though
this seems to work properly {% set groups = integration_entities('group') | select('match', 'light.') | list %} {% set hue_groups = states.light |selectattr('attributes.is_hue_group','eq',true) | map(attribute='entity_id')|list %} {% set members = groups | expand | map(attribute='entity_id')| list %} {{ states.light | map(attribute='entity_id') | reject('in', groups + members + hue_groups) | list}} though it returns several grouped lights that currently are unavailable, making their group unavailabl
let me try to get those states statements out there. want to move to {{integration_entities('hue')}} at least
probably with {% set hue_groups = expand(integration_entities('hue')) |selectattr('attributes.is_hue_group','defined') | map(attribute='entity_id')|list %}
no that does not work
cant use the | expand on those
You don't need to use expand there
{% set hue_groups = integration_entities('hue')
| select('is_state_attr', 'is_hue_group', true)
| list
%}
But you can't get the members of those groups
exactly... why is that?
why is that anything else to the templating engine than iterating over them as states?
Well, you can use expand, but that will just expand the entity to it's state object
But you can't expand it to it's group members because simply HA doesn't see it as a group, and also doesn't have the information to know what the group members are
As the group isn't defined in HA
HA knows what entity_id are in those hue groups
but I can still use this {{ states.light | map(attribute='entity_id') | reject('in', groups + members + hue_groups) | list}} and it works just perfectly! both using the states or the integration_entities
only caveat are the unavailable groups being ignored, so their members arent rejected
is
Thanks! but I need to get the country_active_alerts not all country_alerts because they are old ones.
should I just change it to
{{ state_attr('binary_sensor.oref_alert_all_areas', 'country_active_alerts') | map(attribute='data') | unique | list }}
?
I need to remember this one in Bold. using integration_entities() is so nice, but iterating those attributes next in the select() was unclear to me.
thanks for explaining once again!
That won't work when you use nested groups
you mean in the hue_groups?
No, the HA groups
this must be safest then after all, I wasnt aware it would also catch the hue_groups, but is does```
{% set groepen = states.light
|selectattr('attributes.entity_id','defined')
| map(attribute='entity_id')
|list %}
{% set leden = groepen| expand | map(attribute='entity_id')| list %}
{{ states.light
| map(attribute='entity_id')
| reject('in', groepen +leden)
| list}}``` and should also catch all nested HA groups. Also, iterating states.lights is quicker than iterating integration_entities('hue'), as that holds many more entitiy_id's...
but again, only misses out on the unavailable groups, which dont have the entity_id attribute, even though they are configured as such.
sorry about that.. please delete above bot.
I wonder if that is a bug, considering the screensot above, and the config_entry being "options": { "group_type": "light", "name": "Kerststerren", "entities": [ "light.ster_links", "light.ster_rechts" ], "hide_members": false
how would it be a bug? it's not in the group domain
hue group?
no
I guess I don't understand what you think is a bug then
the entities going unavailable dont make them lose their membership to a group
but apparently the group does lose its members
why would that even be considered a bug?
because it is
You just contradicted yourself
no
dont make them lose their membership to a group
but apparently the group does lose its members
that's a contradiction
which one is it
yeah na dude, you're contradicting your self, it can't lose members and not lose members, so which is it
Im reading and trying to follow so I can explain it to you
But I can't follow you when you're making contradictions
I meant to say here they shouldnt do that
They don't lose membership, they are just unavailable and aren't considered part of the calculation
and the entity list reflects what's being used to represent the state
well at least the system isnt consistent then, because, checking the helper shows they Are members
also see that json bit from the config_entries
right, which is why I said they don't lose membership
you're saying they do, but they dont
the entity_id attribute contains what entities are used for the current state value
expand uses that when expanding
correct, and thats why I noticed that now
normally we see the unavailable states in those templates, and thats why we always have to exclude unavailable....
yes that could be ...
no could be, that's it
I'm not upset in any way
try to read my responses without thinking i'm being malicious 😉
o believe me, you have trained me to do so 😉
Right, so because you think I'm being mean with my responses, it's ok for you to be meam spirited?
huh, now you lost me.
I'm just explaining how it works and you're here tellling me to be calm when I haven't chastised you at all
well if you say so, I certainly felt that way. but let's call it quits ok. life's too short.
(sorry forgot to press enter)
I'd really not like to get this reaction from you, can you point out exactly where you think I was being unreasonable?
I can see it being part of the contradiction thing but you were contradicting yourself and I'm just trying to clarify what your actual meaning was. Which you then realized you said something backwards. Which happens, I get it.
Yeah but you were contradicting yourself. How else can I say "what you're saying doesn't make sense"
in regards to logic, those were mutually exclusive. It's literally impossible for both those scenarios to be true.
You really can't be upset with a person for pointing that out when they are trying to figure out what you actually mean
I said this:
the entities going unavailable dont make them lose their membership to a group
but apparently the group does lose its members
I probaly should have said:
the entities going unavailable dont make them lose their membership to a group imho
but apparently the group does lose its members
Yes well, maybe it's your definition of membership that is the miss communication here
because membership to me, is that the entity is removed from the group, which doesn't happen because the config is static
I still feel the original was ok: unavailable members dont lose the membership (see screenshot), but they are not listed in the states for the container group (see other shot), which goes unavailable too (expected as both members are)
iow, we can not template those member entities based on their containing groups
Petro stated that above I believe. “They don't lose membership, they are just unavailable and aren't considered part of the calculation”
I think it might just be a miscommunication or misunderstanding of the question
That isn’t a bug, if you were to ask me. It’s like asking how bright it is when the lights are off
I read the code, and it doesn't remove unavailable entities, and they show up in expand
So I even tested it myself, with 1 on entity, one off entity, and one perpetually unavailable entity
expand properly expands everything, so at this point, I'm wondering what you're actually seeing @floral shuttle, so what entity has an unavailable group member and what does epxand show?
@floral shuttle What does
{% for s in expand('light.test_for_marius') %}{{ s.entity_id }}: {{ s.state }}
{% endfor %}
show for you in the template editor when you replace the light entity?
I do see a discrepency in the documentation
it claims that any light group with an unavailable member will be state unknown, which is not true.
(sorry, I wasn’t trying to jump in, I just saw that what was being exchanged could be misinterpreted)
Nevemrind, that's referring to using All Entities
No problem, I'm moving on because it's a simple miss communication mixed with past history.
I understand
You and I have some of that too lol
(But I also know that I don’t always ask the right questions)
Hi
How do I add a third option to this yaml to make the same action as action_keep but will also use switch.boiler ?
Should I just add it on actions and under variables: ?
http://pastie.org/p/2RyZljeZJxOmyzd0wb8CqH
make a 3rd variable, make a 3rd actionable message, make a 3rd trigger waiting, make a 3rd choose
Thanks!
it returns nothing....
are all entities unavailable?
yes, both members
a light group with only unavailable members indeed doesn't seem to show the entity_id attribute
It's been that way for quite some time
http://pastie.org/p/6EHdyYntrbNUKZp4sYeAv1
Does it look fine? just finished.
Try it out
looking at the code, it just inherits the behavior from the general entity object
group:
test_kerstverlichting:
name: Test kerstverlichting
entities:
- light.ster_links
- light.ster_rechts``` does it better...
i.e. it behaves like all entities that go unavailable
So, I'd wager this isn't a bug and you'll be fighting an uphill battle getting the behavior to change.
Yeah, for sure, I bumped the issue for a while, but it ended up closing as stale. I don't expect that to change.
Hopefully you’ve already tried this by now, but yes
@petro, this legacy group entity does show the correct states and entities
Yes, well oldschool groups are very unique
That looks like it's reporting unknown, too
should work, you could remove the duplicated steps by doing something like this:
conditions:
- value_template: "{{ wait.trigger.event.data.action in [action_keep, action_cab] }}"
sequence:
- all your actions
- if: "{{ wait.trigger.event.data.action == action_cab }}"
then:
- turn on boiler
yes, the problem isnt the state of to group itself, but it not showing it has any members
You can't correlate old school groups with new school groups
the core team has made it very apparent that old school groups are dead and will not change. It would be incorrect for anyone to assume new school group behavior should match old school groups
Understood and I haven't taken a look at the specifics to be certain, but just thinking that if the new groups are reporting as unavailable ... that may possibly prevent any additional attributes from being generated. Whereas unknown typically represents the entity is available but the state isn't known and that's why the old groups still have their attributes. However, that's just speculation on my part.
What happens is, there's an availablity property on entity objects, when that property is False, all entities follow the same code path.
yeah sure, that is not what I was trying to bring across. I merely tested it for now in your template.
My main point remains not being able to see those unavailable lights belonging to a group that is unavailable, because its members are. It just doesnt reflect the config entries correctly
I totally get your point, and I agree with it, too 🙂 Just attempting to reason through why it may be the way it is ... and also, the fact that the behavior is unlikely to change
very unlikely
I didnt yet search if someone reported it before. Might be good to do just once, to at least make it open, and possibily get a respsonse from the dev team.
Ultimately, maybe get a suggestion how to find these entities in another way, because it is not a mere scientific question... its a real life case
NSX just said he did and kept it alive for months...
wait, I missed that
this
anyways, I personally use labels over groups in my setup
I have 1 or 2 light groups that are comprised of 2 or 3 lamps in a room
and I only use those groups for the UI, the entities are still flagged individually for my light handling automation
labels + filter for unknown/unavailable in a template is better than groups, imho.
Yep, and before labels, I had a script that acted as a config like "labels"
but my reasoning is strictly because of zwave, for multicast
so I bin zwave entities for multicast, and then just call a normal light/switch.turn_on for all lights that are not zwave
then call everything in parallel
so all lights turn on/off at the same time
Ah, that makes sense. I just like working with label_entities() better than I do expand(). Plus, group management is a pain and the one step I always forget to do when adding a device.
Seeing that doesn't make me feel so bad for my 400+ line scripts anymore 😉
tbh, I should make it a python script, because jinja that complex is like jumping through hoops
what I'm doing there would be rather easy to do in python without all the confusing bullshit
Yup, true. That's going to be my winter project, tbh. Especially for my message handler.
Yeah, that light handler is my most complex script
well maybe not most
I'm waiting for my 2 PRs to get merged to reduce complexity and make a few blueprints for others to use
yes, I also do that, but using labels shows this as unavailable too, effectively blocking the template in the same way: {{label_entities('ha_groep') | expand | map(attribute='entity_id')| list|sort}}
because you labeled the group not the entities in the group
I assign lights to areas, and label them
you then go from the area and filter down to the label
and completely forgo even creating the group
Thanks man!
my lights are all in an area. can have a look what that would help. though some of the areas are way bigger than my current light groups. And I already have more than a few areas..nicely grouped in floors
yes, and that's where labels come into play
so you in fact use a label to replace the individual group?
e.g. all my lights that I have attached to voice contrl have the label target light, and all my logic filters down to what aspect I'm targeting with voice
e.g. if I say "turn off downstairs lights" the script starts at all floors, filters to the downstairs floor, expands the areas in to a single list of entities, then filters to only lights with target light
i.e. there's no reason for groups at all
for this method
I did have to create template lights for this functionality. Which are essentially groups that auto update themselves when I add new entities to areas & labels
i.e. I make 1 change: Add the light, place it in area, optionally add label.
everything else is done for me
I use the target area_id system wide too, and replaced a lot of individual entity_id's. could probably even do more. it's a great feature
@floral shuttle I just submitted a PR to at least document the behavior. No idea if it will get approved but if it isn't in scope to get changed, my opinion is we should make the behavior clear. None of the attributes of group entities are currently documented so hopefully this can be improved. If I got anything wrong in the PR please comment.
ah. didn't see this comment until now. Well, if my PR gets approved, we can make an update later if your issue gets addressed.
I hadn't personally tested it but MariusHvdB showed here, #templates-archived message, that the old style groups set the group to unknown as opposed to unavailable when the entities are unavailable..
ah. I saw that in my own testing but I was overriding the status with dev tools -> states rather than making the entity go unavailable via a legitimate method. That would make sense why the attributes remain then. I'll make a change.
Thanks.
Is it possible to create a template that returns the path to the latest image in a (media) directory? I'm trying to build an automation to show Frigates latest snapshot in a HASS.Agent notification
yes
Hello, i have this working string:
{{ iif(is_state('person.chrissi', 'home'), 'color:green;icon:home;', iif(is_state('person.chrissi', 'test2'), 'color:green;icon:home;', iif(is_state('person.chrissi', 'test'), 'color:blue;icon:building;', 'color:red;'))
how can i add a third iif query, when i add this "iif(is_state('person.chrissi', 'test2'), 'color:green;icon:home;" string after the first one it does not work anymore, some ideas?
just use normal if then instead of nested iif's
or make a dictionary
{% set colors = dict(
home='color:green;icon:home;',
test2='color:green;icon:home;',
test='color:blue;icon:building;',
) %}
{{ colors.get(states('person.chrissi'), 'color:red;') }}
ah okay thanks, i will try it, never worked before with dictionarys 🙂
that's a dictionary 😉
{"home": "color:green;icon:home;", ... } is the same as dict(home='color:green;icon:home;'... )
just a different way of writing it
Can’t help but feeling the legacy groups do it right. Just imagine a group children, and none of them loaded their batteries. So their device goes unavailable. Before (legacy) we got the perfect answer: we don’t know the group because your children can’t be found . In the new groups this now is: you don’t have any group of children, and we can’t show any of their supposed names…
How this can be seen as correct functionality is beyond me really.
Agree completely. I made a comment to that effect in your issue: the proper solution would be to have the group state to be unknown
And yes, the members should show unavailable. But at least they should show.
I have a sensor that is a template of a attribute of a sensor. It’s a url for an image how can I use this in either a webpage or image card ? When I tried setting the sensor as the url it was interpreted as a raw string and not the value of the template.
Hi! I need some inspration on this one: I have a tracker for my dog that detects whether it is home or not_home. Any idea on a robust way to code up a few sensors that detects the "short-walk time" of my dog? Like, I can assume that if the dog lefts home and come back within 30mins, then it's a walk (otherwise it might be a vet visit etc). Ideally, I'd want a sensor that tells me the last duration of the short walk, and a sensor of when that happened. With the duration sensor, I can then cook up statistics about my dog's activity for the past day and week
It looks like the card you are using doesn't accept templates. The people in #frontend-archived would know what cards you can use instead
I usually use trigger-based template sensors for this, but for something easier that can be done purely from the UI you could create an input number helper to record the walk duration and create an automation to update it.
Something along the lines of this: https://dpaste.org/En3XF
You could also have another input number that you simply add 1 to each time the automation runs, so that would count the number of seperate walks. You can feed both into their own "utility meter" helpers that reset however often you want (weekly or monthly?). At the end of all that, you'll have what you need to calculate walks per week/month, average walk length, etc.
I found trigger-based template sensor to be quite insufficient at this (or at least I don't know how to do it easily), especially for dealing with temporarily "unknown" location due to a HA restart, and the fact that I need to filter out walk durations longer than 30 mins... I just saw the SQL platform and that seems like a better way, perhaps??
state-based template sensors are definitely limited, but trigger-based ones retain state across restarts and you can essentially do anything you want with them.
The SQL platform will allow you to look up what a sensor's state has previously been, but I'm not sure why you'd need to do that. It's a lot easier to just record something in a trigger based template sensor when it happens, instead of looking it up later with an SQL query
How would I get the duration of the last short walk, for example, using a trigger based sensor? I found that a trigger based sensor still "recalculates" itself during a restart, because it thinks the input triggers are updated.
@near mountain I converted your message into a file since it's above 15 lines :+1:
The code is very buggy, because I found it difficult to filter out durations longer than 30 mins while keeping it robust against reboots
what happens to device_tracker.airtag_wilber across a restart?
Consider the scenario, the dog made a short walk (< 30 mins), and then a longer walk (>30 mins, which should be dropped and not considered). If now HA restarts, I don't know how to recover the short walk duration because now the last home->not_home->home timestamps are already overwritten to the last >30mins ones.
It resets to unknown temporarily until the sensor reconnects, which happens in less than a minute
But that's not even the issue, because "go_time" and "return_time" only updates on home/not_home transitions. The issue is, I found it difficult to filter out the >30mins duration walks
I didn't test this, but this is what I was thinking: https://dpaste.org/9r7rw
Oh that looks promising. Didn't know the trigger can have conditionals as well. Leme try
edited some errors and tested: https://dpaste.org/wWBPA
Thanks. I think I need to let this.state default to unknown in case it's really unknown, I will play with this. Other than that, is there a way to update the leave_datetime as another sensor without duplicating a bunch of code?
you can define as many sensors as you want underneath the same triggers
I'm not sure when you would want it to show unknown; it should have the last known walk duration. I guess you could change it to unknown if you get a walk > 30 mins, or you get multiple 'leave' or 'arrive' triggers in a row. That would take some extra coding though
I'm getting UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'leave_datetime'. Seems like the attribute is not initialized somehow?
I didn’t put any error handling in it. If the very first trigger is an arrive instead of a leave, it will give you an error because the attribute isn’t created yet
Thanks for the hint! Figured out that the leave event caused an error therefore that happened
All working now! Thaks!
No problem!
Hi, yesterday i got help here with a template that will show me unique data once we getting bombed to know which city is under attack now.
{{ state_attr('binary_sensor.oref_alert_all_areas', 'country_active_alerts') | map(attribute='data') | unique | list }}```
My trigger is when state changed to `on`, but if trigger changed and they launched another attack on different cities I won't get notify because state is the same..
Is there any workaround I can do to make a template trigger that will detect if a new unique city is under attack?
http://pastie.org/p/0AzH5f3Ar3yBbNfIHwRLe4 - This is example of the recent bombs we had here but they were not in the same time so I wasn't able to get notify on the new ones.
the automation - http://pastie.org/p/65kzQm9twxueQ5QmfWbhIb
Thanks!!
Yes, but it isn't easy.
Create a template sensor which lists the cities as a comma separated string. Then trigger on state changes of that template sensor and compare it from_state and to_state to see if any city is added to the list
Oh wow, there's more than 1,220 cities in my country that can be under attack..
I don't mean all the cities in your country, I mean the cities which are under attack according to the sensor
{{ "inputboolean.gardena_selecteur_1_jour" ~ states('sensor.jour_semaine') }} @floral bluff
(But I don't think that's actually what you are looking to do here)
thanks, but that's not what i need. i have already this command
{{ states('input_boolean.gardena_selecteur_1_jour_samedi') }} -> return on or off
Ok? And you want to do what exactly with the second command?
{{ "inputboolean.gardena_selecteur_1_jour" + states('sensor.jour_semaine') }} -> return input_boolean.gardena_selecteur_1_jour_samedi
i need to obtain the boolean value of the last command ( the operation which gave me the string )
{{ states("input_boolean.gardena_selecteur_1_jour") ~ states('sensor.jour_semaine') }}
the command you gave me will only give me the concatened string, which i already have
the idea is to obtain the value of : states('{{ "inputboolean.gardena_selecteur_1_jour" + states('sensor.jour_semaine') }}')
but this command is not working, because it has the wrong syntax
i've tried this one too, i thing i need to escape the ' : states('{{ "inputboolean.gardena_selecteur_1_jour" + states(''sensor.jour_semaine'') }}')
maybe the bracked need to be escaped too ...
(Sorry, this wasn't for you lol)
Ok. So, you need the two values concatenated? Or is this so you can query a third sensor?
In templates, + is addition. ~ is concatenation.
i have two string which i need to concatenate in function of the working day, the string value that i will obtain will refer to a boolean i have parametered in my input_boolean yml file.
If you need the name for a third sensor:
{{ states("input_boolean.gardena_selecteur_1_jour" ~ states("sensor.jour_semaine")) }}
i first need the name of the third sensor ( which i already obtain with the value of the concatened string ) , and then i need the value of this third sensor
That's what that does.
There's an inner states() function for the sensor and then an outer states() function on the concatenated name.
it gave me the value unknow, if it was working, it will gave me the value off
i can't send you a screenshot to show you the result in the development tools :/
Please use imgur or other image sharing web sites, and share the link here.
Image posting is blocked in most channels to discourage people from sharing text as images. Sharing text as images assumes that everybody sees the world as you do, which isn't the case. Some people are colour blind, or have visual impairment that means they can't make sense of an image of text.
You are +, which is addition. You are not using ~, which is concatenation.
Try this:
{% set sensor = "input_boolean.gardena_selecteur_1_jour" ~ states("sensor.jour_semaine") %}
{{ sensor }}
found the error, there was a _ missing 😉
lol that'll do it too 🙂
{{ states("input_boolean.gardena_selecteur_1_jour" ~ states("sensor.jour_semaine")) }} -> {{ states("input_boolean.gardena_selecteur_1_jour_" ~ states("sensor.jour_semaine")) }}
thanks a lot for your help
now i need to put it in my automation 😉
well it seems that the automation does not like concatenate string in entity_id ...
You can't template entity_id like that. You are just trying to do a simple condition?
yes
condition: template
value_template: >-
{{ states("input_boolean.gardena_selecteur_1_jour_" ~ states("sensor.jour_semaine")) | default(0) }}
thanks again 😉
No problem 🙂
{{1}} isn’t truthy enough
i need to cast as boolean ?
Yes. Just add == 1 to the end
still not working, although my boolean is true
Check the trace
i don't understand what you mean
Press the 3 dots to the right of the automation and select traces
If you need help figuring out how to interpret it, hit the three dots again and select download trace. You can paste it to a code share site and post the link
i think i need to put my home assistant in english language to see where is the trace ^^
ok found traces
You’ll need to post the yaml trace, not the image. There’s a lot of information there, you’d have to click around and post hundreds of images
But I can see a condition is evaluating as false, I just can’t tell which condition
it is the template condition
I thought you already said it evaluates true? Can you post the template you are using after you fixed it?
{{ states("input_boolean.gardena_selecteur_1_jour_" ~ states("sensor.jour_semaine")) | default(0) == 1 }}
If you paste that into the template editor in developer tools -> template, what does it show?
Remove the == 1 and tell me what it shows
the state of an input boolean is string "on" or "off", not a boolean
without == 1 it gave me on
but when i remove this in the automation, the condition template still not pass ...
Yep karwosts is right change to == 'on'
ok with == "on" it works
thanks guys 😉
really appreciate your help
now i can continue to automate my water pump 😉
Helly, how can I get the value of today in these sensor ?
https://pasteboard.co/tRJ1pvHNmrZ3.png
are you not allowed to use templates for endity ids? e.g. entity_id: "switch.{{'living_room'}}_detect"
never mind I see the answer in the chat history...
I just found out that the author of this HACS that brings up the binary sensor wrote example of template to notification.
http://pastie.org/p/1PJ0U7Txubzbe8fIoQyJ2v
When I tried to use it it's not getting to the notify part. it stopped at the condition part.
EDIT:
Trace file - http://pastie.org/p/5yOWmQKV7y6WhnZAQPLPhl
Automation - http://pastie.org/p/42k523bZzjT0HzfTZKlUKn
Line 18 should be: value_template: "{{ alerts | length > 0 }}"
Line 22 should also be "התרעות פיקוד העורף: {{ alerts | join(' | ') }}"
http://pastie.org/p/2WGoP9hp8EBsH2SJr0MhD8
Like that?
Yup. That should do it.
So just for next time what did I do wrong?
I'm guessing you copied in the quotes and the UI encoded them.
Mmm. okay thanks bud!
Hey! I have a template sensor where I have some gas prices in the attributes. I want the state to show the cheapest price. I do have a working template for the state, but it breakes the sensor on reload because the attributes does not load without a state. How can I edit my first code so it outputs "unknown" if the attributes has no value? My second code is from ChatGPT but shows "unknown" all the time.
http://pastie.org/p/1RABt90g3DcNmZRGHbcEOl
The first thing to do it to add an availability. After that, assign defaults for your float filters and use select or reject to restrict the values being passed to the min filter to those that are defined and are numbers.
Hmm I will check that out. Thanks!
Hi, I think this is a template issue, feel free to point me somewhere else please- Using the code at https://community.home-assistant.io/t/improved-shopping-list/608232 , I have gotten the base dashboard to populate with the food categories in the template, but clicking on them does not open the new sub-category window. How can I go about troubleshooting this? (The link has a great animated image of what is supposed to happen, for reference)
"availability: true" did it for me alone!
anyone ?
What does ‘the value of today’ mean?
I mean the difference between today 00:01 and now
so if I start the day with value “6000”and now (let’s say 12:40) it’s “6240” I want to have “6240” - “6000” so display “240” in my card
Create a daily resetting utility meter for that
No templates required. You can create them under helpers in the GUI
I have two sensors that reports back fan speed but with the suffix RPM so i can't create an arithmethic mean average senor using helper. Is ther an easy way to achieve this with template or similar?
Thanks I ll try that
Not sure if I m doing it correctly: https://pasteboard.co/HsJN3mvcouEV.png
I m getting the full value and not today value
Reset cycle should be daily, as you want the value for a day, and the offset should be left empty
This will create a new entity which can't be the total value
strange now I got a bigger value for today than the total: https://pasteboard.co/h5kTf4PLP4K4.png
I think every X time it add the total value to the today value
When you set it up, the “delta values” option should be disabled
Thanks look like it's working, the old deleted helper value (with the same name) is still there but now the data increase normally, I ll check it with a full day tomorrow
Any tips?
{{ ['sensor.a',' sensor.b'] | map('states') | map('replace', ' RPM', '') | map('int', 'na') | select('is_number') | average }}
90
{% elif 90 >= state_attr(entiteit,'brightness') | int(0) < 254 %}
254
{% elif 254 == state_attr(entiteit,'brightness') | int(0) %}
0
{% endif %}
This works for a zigbee bulb, but A shelly dimmer reports in percent so that gets calculated back into brightness, giving me 89 instead of 90, so the first line in the if statement is true over and over... help?
i just want to cycle the brightness on buttonpress
Worked like a charm! Thanks!
You need to account for that.
90 * / 2.55 = 35.29 so the Shelly will use 35% internally
35 * 2.55 = 89.25 so HA will use 89 for the brightness.
If you use brightness 89 instead of 90 to check on, you won't have this issue, and you probably won't see the difference (for your Shelly it will be the exact same thing)
89 * 2.55 = 34.9 so it will be rounded to 35%
35 * 2.55 = 89.25 so HA will use 89
So you need to make sure you check on values, and apply values which are the same on a 255 and 100 scale
Hi,
can someone point me into right direction.
Roborock integration proviodind sensor which returns value how long time passed since last cleaning (so relative to current time). However whe I use this sensor in a card, it show absolute time stamp.
How can I make it show time passed since last clean?
Thanks
what card are you using?
Hello everyone, I'm pretty new to HA and I'm working my way towards google sheet automations. Do you know if there is a way to import an image from a link using the google sheet integration? If yes what's the correct code?
Specifically I'm trying to import data from flights passing above through FlightRadar24 integration and I want to also input country flags in my google sheet.
Thanks in advance!
Hey Quick one, is it possible to add values to push notifications? I can not find a template or example on how to achieve this, what I want is when the temp is below 20deg send a PN with the temp value from a zigbee temp sensor. Thanks
action: notify.persistent_notification
data:
message: >-
Hello. The temp of bedroom sensor is {{ states("sensor.temperature")|int(0) }} degrees.
title: Temperature has changed
Put that into an if block with a condition of the sensor being below 20 degrees and you're set.
If you want to get fancy with it, you could use the persistent_notification.create action and add an id to it and just constantly update that notification.
https://www.home-assistant.io/integrations/persistent_notification
And arg... you said push notification, like to a mobile device? The same concept applies.
hi, trying to put an action in one of my cards; in Dev Tools it works perfectly on Actions section.
and on my card it wouldn't for some reason..
entity_4:
entity_id: button.tami4_boil_water
templates:
- yellow_on
- red_off
- red_unavailable
tap_action:
action: button.press
target:
entity_id: button.tami4_boil_water
What am I missing here?
You'll want to ask in #frontend-archived
Thanks and one more question,
http://pastie.org/p/1sjcTBjfQNPCobri3VzF10
I use those button card templates to color my cards depend on state (value).
How can I create a template that will change color if time is right now.
My water machine changes the State to the current timestamp when you press the boil water button on it.
State Attributes
Filter entities
tami
Filter states
Filter attributes
button.tami4_boil_water
Boil water
2024-08-19T12:12:45.599245+00:00 friendly_name: Boil water
Developer of this integration said he can't change the timestamp to another state because it's taken by their API
Could use some help. I'm trying to set a variable in my automation (highlighted) and then use it in one of the actions (highlighted) but getting this error:
Message malformed: Entity {{ thermostat }} is neither a valid entity ID nor a valid UUID for dictionary value @ data['action'][1]['choose'][0]['sequence'][0]['if'][0]['entity_id']
See code here:
https://dpaste.org/WyOpx#L6,25
state conditions can't template entity id. use a template condition
ohhh yeah... I knew that once 🙂
Hello, how do I add a delay between 2 actions in the frontend?
action:
- service: light.turn_on
entity_id: light.main_light
- **delay**: 00:00:30
- service: light.turn_off
entity_id: light.main_light
use a script
is it possible to know if an entity is used (used for example in a script or on an automation... or in lovelace)? I would like to restrict my unavailable notification only to entities that are actually used... I do this with a group, but I was wondering if there is a way to make it without having to update all the time the group with the entity that I would like to track!
some device classes have dynamic icons, e.g. battery has icons that show the value visually. is there a template function that given an entity, gives me the current icon? I want a badge that has the dynamic icon of one entity but shows information from other entities (will do that with a mushroom template badge)
{{ state_attr('sensor.x_battery_level', 'icon') }}
I didn't think icons were generally in the state machine anymore
Yeah, that sadly renders to None
Recent change? That attr shows up for several of my entities
I guess it's up to the integrations, but I think in general icons are not recommended as attributes anymore (it's supposed to come from json files)
Could always derive the icon from the current level, too
some entities still have it though
Well, the device class is already doing that, so I thought why reinvent the wheel
The battery sensor in my case comes from MQTT and only has state class, unit of measurement, device class and friendly name attributes
Before I go and spend weeks of my life goggling, youtube videos and reducing what little hair I have left. Has anyone created an automation/templates etc. For the Roborock official integration? More specifically, I am looking to create a set of buttons for each room in the house, and the cleaning type (vacuum/mop/both). I want to select one or more of the rooms I want, choose the clean settings, then click start, and then robot does what robots do? This dis not incorporated in to the roborock integration yet, and no indication of when it might be. So thought I would give it a go myself.
making an template sensor for daily forecast and my config is saying error for config: Invalid config for 'template' from integration 'sensor' at sensors.yaml, line 158: 'attributes' is an invalid option for 'sensor.template', check: sensors->daily_forecast->attributes
Here is my template: https://dpaste.org/Atcmo
Ok
still getting an error when placed in config.yaml: Invalid config for 'template' from integration 'sensor' at configuration.yaml, line 199: 'state' is an invalid option for 'sensor.template', check: sensors->daily_forecast->state
`sensor:
- platform: template
sensors:
daily_forecast:
friendly_name: Daily Forecast
state: >
{{ states('weather.thermoking')[0].attributes.forecast[0].temperature }}°{{ states('weather.thermoking')[0].attributes.forecast[0].unit }}
attributes:
condition: "{{ states('weather.thermoking')[0].attributes.forecast[1].condition }}"
precipitation_probability: "{{ states('weather.thermoking')[0].attributes.forecast[0].precipitation }}"
wind_speed: "{{ states('weather.thermoking')[0].attributes.forecast[1].wind_speed }}"
humidity: "{{ states('weather.thermoking')[0].attributes.forecast[1].humidity }}"
description: "{{ states('weather.thermoking')[0].attributes.forecast[1].condition }}"`
you're not following the example from the docs
so you're mixing up the old and new template styles
if you just want a quick fix, change state: to value_template:, but you'll probably get another error about duplicate sensor: keys
I'm not sure what i'm mixing up for the templates. "Integration error: value_template - Integration 'value_template' not found."
Daily Forecast Template
What is wrong with this template? - name: "Any Camera Motion Detected" state: > {% set motion_sensors = [ 'binary_sensor.backyard_motion', 'binary_sensor.main_hallway_motion', 'binary_sensor.basement_hallway_motion', 'binary_sensor.basement_storage_motion', 'binary_sensor.garage_motion', 'binary_sensor.kitchen_motion' ] %} {% set active_sensors = motion_sensors | selectattr('state', 'eq', 'on') | list | length %} {{ active_sensors }}
What is wrong?
It doesn't work
Easiest way to achieve this would be to create a binary sensor group through the UI
How can i set a {% set found_alert = False %} In a loop. I 1st set it to false outside the loop then set it true inside the loop but then its false again outside the loop
{% for entity in states.geo_location %}
{% if entity.attributes.source == 'gdacs' and entity.state | int < 80 %}
{% set found_alert = True %}
{{found_alert}}
{{ entity.attributes.description }}
Type: {{ entity.attributes.event_type }} Level: {{ entity.attributes.alert_level }}
Distance: {{ entity.state }} km
{% endif %}
{% endfor %}
{{found_alert}}
{% if not found_alert %}
No GDACS alerts within 80 km
{% endif %}```
True
Green flood alert in Belgium
Type: Flood Level: Green
Distance: 77.1 km
False
No GDACS alerts within 80 km```
Variables in the loop (local) cannot access nor change variables outside the loop (global). To encounter this you will need to uses namespaces to transmit between the local and global scope
oke. checking that
You need to either use expand to get the state objects of the list of entities, or use select by is_state. Currently, the selectattr is telling it to select by a property that doesn't exist.
@white lantern I converted your message into a file since it's above 15 lines :+1:
It's missing the target key (which is the source of the error) and quotes around the templates. If you are going to use a target selector the value should populate the target...
...
- repeat:
for_each: "{{ local_sonos_zones }}"
sequence:
- action: media_player.volume_set
target: "{{ repeat.item }}"
data:
volume_level: "{{ volume }}"
....
If you only what it to be able to access entities (not areas and labels too), use an entity selector... they're more straight forward.
Apprecite the reply! I got a new error, which is always a good sign.
Message malformed: extra keys not allowed @ data['sequence'][0]['repeat']['sequence'][0]['volume_level']
It looks like it doesn't like volume_level, but that's... sort of important 🙂
I'm a dummy. It needed a data key
I was editting above, it's missing data
data:
target:
etc....
Thank you @haughty breach 🙂
Interesting - it's not erroring, but it's also not doing anything
What are you doing to fire it?
I have it being called as part of an automation, and then I'm also clicking "Run script" and executing it
When I listen to events I see:
- Automation runs
- Set sonos volume script runs
- I don't actually see the selected entity being passed into the script listed anywhere in the script run
- Script stops
- Automation stops
And just in case this is helpful, here's the event:
event_type: call_service
data:
domain: script
service: set_sonos_volume
service_data:
sonos_zones:
entity_id:
- media_player.dormitorio
volume: 0.21
origin: LOCAL
I guess you want
target:
entity_id: "{{ repeat.item }}"
So if I add target it kicks it back saying that extra keys are not allowed
This has veered into #automations-archived territory, but I would use an entity selector... target selectors are finicky IMO... https://dpaste.org/t1q8m
I can do that -- can I get the entity id from the entity selector?
When I tried that it listed the device_id
Oh boiiiii. It works.
Yes, you will get an entities dropdown... you can even add the integration to the filter so only Sonos media players appear in the list
That's perfect -- I'll look up how to do that now
I'm making this template form my daily agenda automation to give me a daily morning summary. I can't figure out what I need to do or fix to have this automation work. My trace error is: Stopped because an error was encountered at August 21, 2024 at 7:44:19 AM (runtime: 0.04 seconds) UndefinedError: 'daily_forecast' is undefined Here is the yaml: https://dpaste.org/HH8OH
You need to fix the name of the response variable... currently it's: response_variable: weather.get_forecasts
What would I change it too?
daily_forecast
Yes... response_variable: daily_forecast
its working but getting errors in some responses with the diffrent calendars. https://i.imgur.com/cqfOhNV.jpg
Alexa just spit out a bunch of errors for entities
This is probably better suited for #voice-assistants-archived or #automations-archived. Based on the trace it seems like the error message (hallucination?) is coming from the LLM response. On the template front, I would suggest using a macro instead of repeating essentially the same template for each calendar/agenda.
may i ask what a macro is as idk that one?
is there a site we can send a video of my alexa issue for troubleshooting?
ok im reading it now. the automations is from a blueprint i took control of and is just modifying it to make it work with accuweather daily forecast