#templates-archived

1 messages · Page 82 of 1

inner mesa
#

no

#

{{ (states('number.somenumber')|float(0) * 1.1) | int }}

#

(float * 1.1) is nothing

abstract maple
#

Aaaah Ok. I would never have guessed that...

#

Thanks.

inner mesa
#

it's just order of operations

#

| binds tightly

abstract maple
#

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

inner mesa
#

you can write one

#

{{ [11, 10]|sort|min }}

#

-> 10

#

{{ [5, 10]|sort|min }} -> 5

abstract maple
#

yes that'll do.

inner mesa
#

{{ ([0, -10, 10]|sort)[1] }}

#

that clamps both min and max

#

middle value is the variable

abstract maple
#

That's a cool trick, gotta remember that...

plain magnetBOT
#

@frozen galleon I converted your message into a file since it's above 15 lines :+1:

lucid thicket
#

You’ll also have to change sensor entity names if they don’t match yours

edgy umbra
#

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```
frail dagger
marble jackal
#

@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

edgy umbra
stuck sedge
#

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?

obtuse zephyr
marble jackal
edgy umbra
#

Didn’t know this was available! 🙂

sonic sand
#

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!

silver rose
#

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.

winter forge
#
{{ 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

last basin
#

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

marble jackal
#

Using an SQL sensor to get it out of the database, or use something like this

last basin
#

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?)

marble jackal
#

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

last basin
#

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

marble jackal
edgy umbra
#

How can i get rid of the number after the dot?

#
    float(0) * 1000 %}```
#

It now show 213.5 for example

inner mesa
#

You either truncate it by converting it into an integer or you round it

#

Surround it in parentheses and add |int or |round

edgy umbra
#

This seems not working?

#
    float(0) * 1000 | int) %}```
inner mesa
#

Your closing parens should be after the 1000

#

Consider what you're doing

sacred sparrow
#

is there a way I can make this work:

target:
  entity_id: {{ states.light | selectattr('state', 'eq', 'on') | map(attribute='entity_id') }}```
marble jackal
#

Yes, by adding a list filter, and wrapping the template in quotes

sacred sparrow
#

perfect! that worked 🙂

sacred sparrow
#

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 }}

marble jackal
#

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
  }}
sacred sparrow
#

ah perfect thank you again

sonic sand
#

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!

fossil venture
#
    action:
      service: mqtt.publish
      data:
        topic: >
          homeassistant/persistence/{{ trigger.to_state.name | lower }}
        payload: >
          {{ now() }}
        retain: true
sonic sand
fossil venture
#

I suspect so. The documentation has not been updated yet.

steel swift
#

I gave the wrong data, and I cant delete this?

fossil venture
#

It's gone.

steel swift
#

Ty

plain magnetBOT
#

@steel swift I converted your message into a file since it's above 15 lines :+1:

marble jackal
steel swift
marble jackal
#

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)

steel swift
#

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.

steel swift
marble jackal
#

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

mighty ledge
silver rose
bronze prawn
#

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'>
lucid thicket
#

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

bronze prawn
#

okay. So something else is going on though I can tell you that the service call succeeds just by adding the quotes. Weird

lucid thicket
#

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

bronze prawn
#
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?

inner mesa
#

Yes

bronze prawn
#

I am up for trying this but I don't know how to do what you are proposing

lucid thicket
#

Yes, but I’m suggesting putting it in JSON form

bronze prawn
#

Could I trouble you to educate me on how I might do that?

frail dagger
#

In your Python script, what is amount defined as? Are you using a type hint with it?

bronze prawn
lucid thicket
#

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"}
  }}
frail dagger
bronze prawn
bronze prawn
lucid thicket
#

is that with my updated edit, with the double curly braces?

#

If that doesn't work, I'm out of ideas

bronze prawn
#

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

frail dagger
#

Give me a sec.

mighty ledge
#

it's complaining about currencyfrom

#

are you sure you're looking at the most up-to-date error @bronze prawn ?

bronze prawn
mighty ledge
#

You can't run templates through the service caller.

bronze prawn
#

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?

frail dagger
#

You should, yeah.

plain magnetBOT
#

@bronze prawn I converted your message into a file since it's above 15 lines :+1:

bronze prawn
#

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?

mighty ledge
#

why are you doing it in variables?

#

that forces HA to resolve the template type

#

just put those templates in data's output

bronze prawn
#
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

mighty ledge
#

No

#

You have to return the entire data section like @lucid thicket pointed out

bronze prawn
#

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?

frail dagger
bronze prawn
frail dagger
#
if amount is none:
  amount = 1
#

(simplified format)

#

There, even easier.

bronze prawn
#

Thanks much.

abstract maple
#

Hey all, is there a template-ish way to get at the options available for a select.something entity?

frail dagger
abstract maple
#

so if we amend that by [1] we would get the first option, right?

inner mesa
#

That will get the second option

abstract maple
#

🤦‍♂️ If I mix up zero-footed and one-footed lists, it's probably time to call it a day...

frail dagger
#

There’s also a action that will get the first or last option as well without having to use a template at all.

abstract maple
#

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...

frail dagger
abstract maple
#

Like chores you mean...

frail dagger
abstract maple
#

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...

still geode
#

can i style text in a template like italic bold etc? im using mushroom template card.

frail dagger
atomic blade
#

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

marsh cairn
atomic blade
#

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?

atomic blade
#

A little surprising that function doesn't cause template updates since I'm pretty sure there are events you can listen for

frail vale
#

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!

lucid thicket
atomic blade
#

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

lucid thicket
#

sounds like you need a trigger-based template sensor instead of a state-based one

atomic blade
#

Well maybe, but I was just wondering if there was a way to do it with a template

marble jackal
#

@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

atomic blade
marble jackal
#

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

atomic blade
#

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

marble jackal
#

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

atomic blade
#

Yeah exactly. I've just created an automation that updates it about every day

mighty ledge
#

Only way templates register entities for listening is if you access the state object.

marble jackal
#

why not create a trigger based template sensor then?

mighty ledge
#

which you aren't doing

atomic blade
marble jackal
#

huh

{{
  integration_entities('iBeacon Tracker')
    | expand
    | map(attribute='entity_id')
    | list
}}

this only returns 2 entities

#
{{  integration_entities('iBeacon Tracker') }}

This returns 38

atomic blade
#

async_track_state_added_domain seems like the closest thing I'd be looking for from looking at the docs

marble jackal
#

shouldn't be the same list?

atomic blade
#

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?

mighty ledge
atomic blade
#

Although actually that doesn't sound completely right.

mighty ledge
#

they only listen to state change events

marble jackal
#

ah right, integration_entities() shows disabled entities

atomic blade
#

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

mighty ledge
#

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

atomic blade
#

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?

opaque sentinel
#

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

mighty ledge
mighty ledge
#
{% 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 ^

opaque sentinel
opaque sentinel
#

Guess I need to convert the state to an int somewhere?

mighty ledge
#

No, you need to add an availability to it

#

are you making this in the UI or via yaml?

opaque sentinel
#

yaml

#

Haven't crossed my mind that it can be done in the ui tbh

mighty ledge
#

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.

marble jackal
#

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

opaque sentinel
#

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?

mighty ledge
#

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

limber sonnet
#

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

mighty ledge
#

it does on-the-hour

limber sonnet
#

ah so it doesn't depend on homeassistant boot time

mighty ledge
#

it used to, way back in the day

limber sonnet
#

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?

mighty ledge
#

depends on what you're doing

#

in the template

limber sonnet
#

getting data from my weather entity for the next 6 houres

mighty ledge
#

probably fine

#

only concern would be if it causes you to hit api limits

#

depending on the weather service you use

limber sonnet
#

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

mighty ledge
#

it depends on the integration

limber sonnet
#

im using openweather

mighty ledge
#

🤷‍♂️ without looking at the code, I can't tell you if it does or doesn't

limber sonnet
#

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

mighty ledge
#

It very well could cache the data

#

I don't have it memorized, I also use that

limber sonnet
#

mhm i will keep an eye on the api usage for now

near mountain
#

Does the UI support editing a template sensor with trigger?

inner mesa
#

Nope

plain magnetBOT
#

@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:

lapis hound
#

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

marble jackal
#

well, you are provding an inoccorrect device_class. Remove the line wiht device_class: light

plain magnetBOT
#

@lapis hound I converted your message into a file since it's above 15 lines :+1:

lapis hound
#

Which says state is invalid. What do I need to put there instead?

#

Is it supposed to be available and unavailable?

marble jackal
#

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

lapis hound
#

I still want to be able to display the number of lights. I am trying to use the new badges.

plain magnetBOT
#

@lapis hound I converted your message into a file since it's above 15 lines :+1:

lapis hound
#

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

marble jackal
#

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

steel swift
acoustic urchin
#

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.

lucid thicket
mighty ledge
#

there's probably an error in there. {{ this.state | default(0) | float + decrease }}

fleet trout
#

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

mighty ledge
#

that's just an automation and normal conditions that you can build with the UI

#

and & or are normal conditions you can select

frail dagger
#

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.

mighty ledge
#

That's still probably doable without templates

#

sensor group with type set to maximum. Then use that as a trigger above 0

frail dagger
#

Oooohhh yeah, that could work too.

willow wing
#

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

inner mesa
#

Like this?
{{ 'foo bar'.split()|first }} -> foo

willow wing
mighty ledge
#

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

willow wing
willow wing
#

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"

steady spindle
#

hi @willow wing . What do you want to do ? Looks like it is related to "Waste collect " .... is it coming from a calendar or ...?

willow wing
#

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

marble jackal
#

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

willow wing
#

" " does not work for "in x days" it does work only for the label when i need [0]

steady spindle
#
{% 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`
marble jackal
#

So what do you want as result?

input: Restabfall in x Tagen > output: ??
input: Restabfall Morgen > output: ??
willow wing
#

{{ 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]

marble jackal
#

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

willow wing
#

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]

willow wing
willow wing
marble jackal
#

{{ states("sensor.nachste_abholung").split(" ")[0] }} will give Restabfall
{{ states("sensor.nachste_abholung").split(" ")[1:] | join(' ') }} will give the other thing you want

willow wing
#

Restabfall is possible with that string "{{ states("sensor.nachste_abholung").split(" ")[0] }}"

the problem is the second one with the both values

willow wing
marble jackal
#

value sack?

willow wing
#

Sack in x Tagen is the output, but should be only "in x Tagen"

steady spindle
#

of cource, we print both ! 😉

marble jackal
#

You never mentioned Sack before. You said the state was Restabfall in x Tagen

#

So what is the actual state of that sensor

willow wing
#

oh your right sorry, gelber sack is a other vlaue that it can be - Gelber Sack, Restabfall, Papiertonne and Hackgut

#

sorry my misstake

steady spindle
#

ROFL 😉

marble jackal
#

so in that case you want it to be Gelber Sack and in 2 Tagen?

willow wing
#

yep

#

or Morgen

steady spindle
#

=> So a table of "keywords" to split the line , and the "end of line" ? I'ts becoming funny 😉

willow wing
#

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

marble jackal
#

{{ states("sensor.nachste_abholung").split(" ")[:2] | reject('in', ['in', 'Morgen']) | join(" ") }}
{{ states("sensor.nachste_abholung").split(" ")[1:] | reject('eq', 'Sack') | join(' ') }}

willow wing
#

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] }}

marble jackal
#

Gelber Sack is 2 words, that makes it a bit more complicated

marble jackal
willow wing
#

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(' ') }}

marble jackal
willow wing
#

{{ 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

marble jackal
#

I'm not talking about that one

willow wing
#

my msistake again

#

i have updated the first one now too

inner mesa
#

Maybe you have enough to experiment on your own?

plain magnetBOT
#

@gilded raven I converted your message into a file since it's above 15 lines :+1:

gilded raven
inner mesa
#

what if it's none of those?

gilded raven
#

then off I suppose

inner mesa
#

then:
{{ states('sensor.whatever') in ['On', 'Buffering', 'Playing'] }}

gilded raven
#

so {{ states('media_player.playstation_4') in ['On', 'Buffering', 'Playing'] }}

inner mesa
#

you missed a ]

gilded raven
#

edited

inner mesa
#

yes

mighty ledge
#

those aren't the correct states

#

those are translated states

#

you need the untranslated ones from developer tools -> states page

inner mesa
#

yeah, you need to review devtools -> States for what they actually are

gilded raven
inner mesa
#

you'll need to find out

gilded raven
#

history?

#

can i look at the raw state history?

inner mesa
#

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

gilded raven
#

and what would be the correct device class for this?

#

power looks wrong as it's labeled 'Clear' when off

inner mesa
#

this is best done when you're in front of the thing, rather than while you're away

gilded raven
mighty ledge
#

frontend

gilded raven
#

so network tab could help me

mighty ledge
#

not sure what "network" tab is

gilded raven
#

in devtools

mighty ledge
#

there is no network tab

#

Yaml, states, actions, template, events, statistics, assist

gilded raven
#

not HA devtools, chrome devtools

#

anyway yeah i'll have to do it when i get home then

mighty ledge
#

yes, potentially

gilded raven
#

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

mighty ledge
#

if you just want on/off in the ui, choose nothing

#

power will give you on/off, motion is detected/clear

gilded raven
#

is it not updating then?

mighty ledge
#

clear your cache & try again

gilded raven
mighty ledge
#

Yes

gilded raven
#

just went on a different browser entirely and it still says clear/detected

mighty ledge
#

are you sure you have Power selected?

#

looks like a bug

gilded raven
mighty ledge
mighty ledge
gilded raven
mighty ledge
#

click the x

gilded raven
#

I did. Upon saving, then going back into it, it's back to being power

mighty ledge
#

this is a UI created template entity?

gilded raven
mighty ledge
#

did you click submit after clicking x?

gilded raven
#

yes

mighty ledge
#

🤷‍♂️ working for me

#

delete that and create a new one, don't specify the device_class

peak juniper
#

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" ??

gritty ledge
#

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

mighty ledge
#

keep in mind, if the state is the same, it will appear as if it wasn't recalculated.

gritty ledge
#

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

mighty ledge
#

can you just post the template?

#

there's no way the minutely rendering is failing

#

there's likely an issue in your template

gritty ledge
#

why wasn't it failing when I pasted the entire thing into the template editor then

mighty ledge
#

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.

gritty ledge
plain magnetBOT
#

@gritty ledge I converted your message into a file since it's above 15 lines :+1:

gritty ledge
#
   {% endif %}
  {% endfor %}
{% endmacro %}
``
mighty ledge
#

That should calc fine through restarts, though you are overwriting now which you shouldn't do

#

also, today_at registers templates for minutely updates

gritty ledge
#

generally works fine but sometimes it seems to get stuck

#

restart fixes it when it happens

mighty ledge
#

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

rustic hull
#

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

rustic hull
#
- 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

fleet trout
# mighty ledge sensor group with type set to maximum. Then use that as a trigger above 0

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 😄

frail dagger
fleet trout
#

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)

frail dagger
#

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.

fleet trout
#

that sounds pretty easy

frail dagger
#

It is 🙂

fleet trout
#

🙈

frail dagger
#

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
fleet trout
#

ok i think ill have to figure out what the heating entities are... it doesnt appear under members when choosing sensor group

frail dagger
#

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.

fleet trout
#

its a "climate" thing

frail dagger
#

Oh! They're climate entites?

fleet trout
#

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"
frail dagger
#

Ok. Those are climate entites then.

fleet trout
#

and they dont like to appear in groups right? 😄

#

probably shy

frail dagger
#

Well, they can (using old style groups). But, you really only care about the temps on them for this, right?

fleet trout
#

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

frail dagger
#

Ok and that's an attribute?

fleet trout
#

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

frail dagger
#

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.

fleet trout
#

oh yes, its attribute "command_value"

frail dagger
#

Ok.

fleet trout
#

well that page is nice

frail dagger
#

So, slightly different approach here. How many of them do you have?

fleet trout
#

19 or 20 around

frail dagger
#

And they are your only climate devices?

fleet trout
#

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

frail dagger
#

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)

fleet trout
#

ive got some more apparently 😄

#

but the ones we need all begin with "fbh_"

#

like this climate.fbh_eg_elw_wohnzimmer

frail dagger
#

Ok. Give me a sec and I'll have something for you.

fleet trout
#

so that means... code in progress?

#

😄

frail dagger
#

I live up to my name 🤣

fleet trout
#

😄

#

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 😄

frail dagger
#

No. Well, yes, but no. The froontend can do JS, but for anything in the backend, it's all python and jinja.

rough glade
#

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

mighty ledge
#
  1. 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.
rough glade
#

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

frail dagger
#

KNX help

rough glade
#

I was using block quote instead of code block. that's what you get for reading the markdown page too fast

rough glade
marble jackal
#

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

rough glade
#

It's not changing from unknown

mighty ledge
#

are you 100% sure that trigger works?

rough glade
#

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!"

plain magnetBOT
#

@jaunty wyvern I converted your message into a file since it's above 15 lines :+1:

mighty ledge
#

Please stop double posting, we can see your initial post.

marble jackal
#

If you want English, you can use strftime

mighty ledge
#
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") }}"
marble jackal
#

%A for the weekday, %b for the abbreviated month

#

Just like that

opaque sentinel
#

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

mighty ledge
#

This channel is specific to Jinja templates, not anything that includes the word "template"

floral shuttle
#

and if you hop over, please dont post screenshots, but properly formatted yaml

opaque sentinel
#

Figured this was the best way to include the directories, but in hindsight maybe not.

jaunty wyvern
marble jackal
flat gulch
#

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

frail dagger
flat gulch
#

same thing, still reporting as false no matter which way I flip the comparison

frail dagger
#

Oh wait... did you create the weather sensor using the get_forecasts() action call?

flat gulch
#

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

plain magnetBOT
#

@flat gulch I converted your message into a file since it's above 15 lines :+1:

frail dagger
#

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?

flat gulch
#

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

frail dagger
#

That's really weird! Let me test it here.

flat gulch
#

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

frail dagger
#

I inverted the < to > to make it true, but yeah... I'm not sure what's going on with yours tbh.

flat gulch
#

i am stupid basically lol

frail dagger
flat gulch
#

i was putting the whole yml and not the just the state yml

frail dagger
#

LMFAO... that'll do it.

#

Well, at least that mystery is solved.

flat gulch
#

i saw the warning above the state template, but the documentation always had the template: -binary_sensor thing, so i always included it...

marble jackal
#

Doesn't it warm against that now, or are you but on 2024.8 yet?

flat gulch
#

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

marble jackal
#

That's all under the YAML configuration header

#

But only skimming it will make you miss that 🙂

frail dagger
#

Yeah, it does warn against it now in 2024.8.

frail dagger
flat gulch
#

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

frail dagger
#

Eh, no worries... people here can attest to some of my, um, stupider moments...

#

-# that I still have

near mountain
#

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
#

Oh nvm, figured it out --- need to drop the timestamp()

plain magnetBOT
#

@kindred garden I converted your message into a file since it's above 15 lines :+1:

kindred garden
#

Any help would be mega appreciated :)

plain magnetBOT
#

@kindred garden I converted your message into a file since it's above 15 lines :+1:

kindred garden
#

This one is what I have so far, apologies ^

lucid thicket
kindred garden
#

Yeah I realised that and removed it

#

but I'm still experiencing the same issue with the icon not appearing

lucid thicket
#

What do you get if you paste that template into the template editor in developer tools

plain magnetBOT
#

@kindred garden I converted your message into a file since it's above 15 lines :+1:

kindred garden
#

Huh, that's odd.

#

It removes that chunk but leaves the other one

lucid thicket
#

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).

kindred garden
#

Thank you, I'll give that a go.

lean canyon
#

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 }}

marble jackal
#

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

lean canyon
#

Ok, so if I have response_variable: testing How to get the response?

marble jackal
#

{{ testing.response.speech.plain.speech }}

lean canyon
#

Now I think I got it. Thanks

sonic sand
#

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

marble jackal
#

What's the city name? Is that what's after title?

marble jackal
#

Also, please don't use images to share text

sonic sand
sonic sand
#

I guess it has something to do with

{{country_active_alerts[0].data}}
lucid thicket
floral shuttle
#

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}}

marble jackal
#

Oh wait, I misread

floral shuttle
#

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

marble jackal
#

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
}}
floral shuttle
#

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

marble jackal
#

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

floral shuttle
#

exactly... why is that?

#

why is that anything else to the templating engine than iterating over them as states?

marble jackal
#

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

floral shuttle
#

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

sonic sand
floral shuttle
#

thanks for explaining once again!

marble jackal
floral shuttle
#

you mean in the hue_groups?

marble jackal
#

No, the HA groups

floral shuttle
#

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

mighty ledge
#

how would it be a bug? it's not in the group domain

floral shuttle
#

it is?

#

its a group helper

mighty ledge
#

hue group?

floral shuttle
#

no

mighty ledge
#

I guess I don't understand what you think is a bug then

floral shuttle
#

the entities going unavailable dont make them lose their membership to a group

#

but apparently the group does lose its members

mighty ledge
#

why would that even be considered a bug?

floral shuttle
#

because it is

mighty ledge
#

You just contradicted yourself

floral shuttle
#

no

mighty ledge
#

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

floral shuttle
#

indeed, called a bug

#

please read first before chastising me

mighty ledge
#

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

floral shuttle
mighty ledge
#

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

floral shuttle
#

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

mighty ledge
#

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

floral shuttle
#

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....

mighty ledge
#

You're remembering old school groups

#

not new domain groups.

floral shuttle
#

yes that could be ...

mighty ledge
#

no could be, that's it

floral shuttle
#

hey calm down a bit please

#

i was being friendly

mighty ledge
#

I'm not upset in any way

#

try to read my responses without thinking i'm being malicious 😉

floral shuttle
#

o believe me, you have trained me to do so 😉

mighty ledge
#

Right, so because you think I'm being mean with my responses, it's ok for you to be meam spirited?

floral shuttle
#

huh, now you lost me.

mighty ledge
#

I'm just explaining how it works and you're here tellling me to be calm when I haven't chastised you at all

floral shuttle
#

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)

mighty ledge
#

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.

floral shuttle
mighty ledge
#

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

floral shuttle
#

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

mighty ledge
#

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

floral shuttle
#

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

languid pendant
#

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

mighty ledge
#

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.

languid pendant
#

(sorry, I wasn’t trying to jump in, I just saw that what was being exchanged could be misinterpreted)

mighty ledge
mighty ledge
languid pendant
#

I understand

#

You and I have some of that too lol

#

(But I also know that I don’t always ask the right questions)

sonic sand
#

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

mighty ledge
#

make a 3rd variable, make a 3rd actionable message, make a 3rd trigger waiting, make a 3rd choose

mighty ledge
#

are all entities unavailable?

floral shuttle
#

yes, both members

marble jackal
#

a light group with only unavailable members indeed doesn't seem to show the entity_id attribute

floral shuttle
#

yes that is exactly what made me wonder

#

imho, it shouldnt

obtuse zephyr
#

It's been that way for quite some time

mighty ledge
#

Try it out

mighty ledge
floral shuttle
#
group:
  test_kerstverlichting:
    name: Test kerstverlichting
    entities:
      - light.ster_links
      - light.ster_rechts``` does it better...
mighty ledge
#

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.

obtuse zephyr
#

Yeah, for sure, I bumped the issue for a while, but it ended up closing as stale. I don't expect that to change.

lucid thicket
floral shuttle
#

@petro, this legacy group entity does show the correct states and entities

mighty ledge
#

Yes, well oldschool groups are very unique

obtuse zephyr
#

That looks like it's reporting unknown, too

marble jackal
floral shuttle
mighty ledge
#

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

obtuse zephyr
#

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.

mighty ledge
floral shuttle
#

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

obtuse zephyr
#

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

mighty ledge
#

very unlikely

floral shuttle
#

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

mighty ledge
#

NSX just said he did and kept it alive for months...

floral shuttle
#

wait, I missed that

obtuse zephyr
mighty ledge
#

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

frail dagger
#

labels + filter for unknown/unavailable in a template is better than groups, imho.

mighty ledge
#

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

frail dagger
#

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.

frail dagger
#

Seeing that doesn't make me feel so bad for my 400+ line scripts anymore 😉

mighty ledge
#

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

frail dagger
#

Yup, true. That's going to be my winter project, tbh. Especially for my message handler.

mighty ledge
#

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

floral shuttle
mighty ledge
#

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

floral shuttle
#

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

mighty ledge
#

yes, and that's where labels come into play

floral shuttle
#

so you in fact use a label to replace the individual group?

mighty ledge
#

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

floral shuttle
#

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
#

as for the closed because stale issue. I've mentioned it in a new issue

lucid thicket
# obtuse zephyr https://github.com/home-assistant/core/issues/77511

@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.

lucid thicket
obtuse zephyr
lucid thicket
#

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.

opaque sentinel
#

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

mighty ledge
#

yes

opaque sentinel
#

Great, thanks!

#

...how would I do it? Some sort of find shell command perhaps?

willow wing
#

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?

mighty ledge
#

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;') }}
willow wing
#

ah okay thanks, i will try it, never worked before with dictionarys 🙂

mighty ledge
#

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

floral shuttle
#

How this can be seen as correct functionality is beyond me really.

lucid thicket
floral shuttle
#

And yes, the members should show unavailable. But at least they should show.

patent shadow
#

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.

near mountain
#

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

lucid thicket
lucid thicket
# near mountain Hi! I need some inspration on this one: I have a tracker for my dog that detects...

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.

near mountain
lucid thicket
#

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

near mountain
plain magnetBOT
#

@near mountain I converted your message into a file since it's above 15 lines :+1:

near mountain
#

The code is very buggy, because I found it difficult to filter out durations longer than 30 mins while keeping it robust against reboots

lucid thicket
#

what happens to device_tracker.airtag_wilber across a restart?

near mountain
near mountain
#

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

lucid thicket
near mountain
lucid thicket
near mountain
lucid thicket
#

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

near mountain
lucid thicket
#

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

near mountain
#

All working now! Thaks!

lucid thicket
sonic sand
#

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!!
marble jackal
#

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

sonic sand
#

Oh wow, there's more than 1,220 cities in my country that can be under attack..

marble jackal
#

I don't mean all the cities in your country, I mean the cities which are under attack according to the sensor

frail dagger
#

{{ "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)

floral bluff
#

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

frail dagger
#

Ok? And you want to do what exactly with the second command?

floral bluff
#

{{ "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 )

frail dagger
#

{{ states("input_boolean.gardena_selecteur_1_jour") ~ states('sensor.jour_semaine') }}

floral bluff
#

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 ...

frail dagger
#

(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.

floral bluff
#

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.

frail dagger
#

If you need the name for a third sensor:

{{ states("input_boolean.gardena_selecteur_1_jour" ~ states("sensor.jour_semaine")) }}
floral bluff
#

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

frail dagger
#

That's what that does.

#

There's an inner states() function for the sensor and then an outer states() function on the concatenated name.

floral bluff
#

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 :/

plain magnetBOT
#

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.

floral bluff
frail dagger
floral bluff
#

same result

frail dagger
#

Try this:

{% set sensor = "input_boolean.gardena_selecteur_1_jour" ~ states("sensor.jour_semaine") %}
{{ sensor }}
floral bluff
#

found the error, there was a _ missing 😉

frail dagger
#

lol that'll do it too 🙂

floral bluff
#

{{ 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

frail dagger
#

hahaha nice.

#

No problem 🙂

floral bluff
#

now i need to put it in my automation 😉

#

well it seems that the automation does not like concatenate string in entity_id ...

frail dagger
#

You can't template entity_id like that. You are just trying to do a simple condition?

floral bluff
#

yes

frail dagger
#
condition: template
value_template: >-
  {{ states("input_boolean.gardena_selecteur_1_jour_" ~ states("sensor.jour_semaine")) | default(0) }}
floral bluff
#

thanks again 😉

frail dagger
#

No problem 🙂

floral bluff
#

i will remember this 😉

#

strange the template always return false ...

lucid thicket
#

{{1}} isn’t truthy enough

floral bluff
#

i need to cast as boolean ?

lucid thicket
#

Yes. Just add == 1 to the end

floral bluff
#

still not working, although my boolean is true

lucid thicket
#

Check the trace

floral bluff
#

i don't understand what you mean

lucid thicket
#

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

floral bluff
#

i think i need to put my home assistant in english language to see where is the trace ^^

#

ok found traces

lucid thicket
#

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

floral bluff
#

it is the template condition

lucid thicket
#

I thought you already said it evaluates true? Can you post the template you are using after you fixed it?

floral bluff
#

{{ states("input_boolean.gardena_selecteur_1_jour_" ~ states("sensor.jour_semaine")) | default(0) == 1 }}

lucid thicket
#

If you paste that into the template editor in developer tools -> template, what does it show?

floral bluff
#

it gave me false

#

but i dont understand why ...

lucid thicket
#

Remove the == 1 and tell me what it shows

lofty mason
#

the state of an input boolean is string "on" or "off", not a boolean

floral bluff
#

without == 1 it gave me on

#

but when i remove this in the automation, the condition template still not pass ...

lucid thicket
#

Yep karwosts is right change to == 'on'

floral bluff
#

ok with == "on" it works

#

thanks guys 😉

#

really appreciate your help

#

now i can continue to automate my water pump 😉

half fable
plucky heron
#

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...

sonic sand
frail dagger
#

Line 22 should also be "התרעות פיקוד העורף: {{ alerts | join(' | ') }}"

frail dagger
#

Yup. That should do it.

sonic sand
#

So just for next time what did I do wrong?

frail dagger
#

I'm guessing you copied in the quotes and the UI encoded them.

sonic sand
#

Mmm. okay thanks bud!

jolly crest
#

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

haughty breach
#

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.

jolly crest
#

Hmm I will check that out. Thanks!

obtuse lava
#

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)

jolly crest
lucid thicket
half fable
marble jackal
#

Create a daily resetting utility meter for that

#

No templates required. You can create them under helpers in the GUI

half pendant
#

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?

half fable
half fable
marble jackal
#

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

half fable
lucid thicket
half fable
#

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

marble jackal
acoustic arch
#
      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

marble jackal
# acoustic arch ``` {% if state_attr(entiteit,'brightness') | int(0) < 90 %} 90 {% ...

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

velvet sigil
#

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

mighty ledge
#

what card are you using?

velvet sigil
#

VAcuum Map Card

signal mauve
#

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!

storm tide
#

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

frail dagger
#

Put that into an if block with a condition of the sensor being below 20 degrees and you're set.

#

And arg... you said push notification, like to a mobile device? The same concept applies.

sonic sand
#

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?

sonic sand
#

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
sonic sand
#

Developer of this integration said he can't change the timestamp to another state because it's taken by their API

bronze prawn
#

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

lofty mason
#

state conditions can't template entity id. use a template condition

bronze prawn
#

ohhh yeah... I knew that once 🙂

burnt vault
#

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
marble jackal
#

use a script

hollow girder
#

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!

split pivot
#

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)

obtuse zephyr
#

{{ state_attr('sensor.x_battery_level', 'icon') }}

lofty mason
#

I didn't think icons were generally in the state machine anymore

split pivot
#

Yeah, that sadly renders to None

obtuse zephyr
#

Recent change? That attr shows up for several of my entities

lofty mason
#

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)

obtuse zephyr
#

Could always derive the icon from the current level, too

lofty mason
#

some entities still have it though

split pivot
#

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

pallid birch
#

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.

knotty idol
#

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

inner mesa
#

You put the template sensor in sensors.yaml

#

It belongs in configuration.yaml

knotty idol
#

Ok

knotty idol
# inner mesa You put the template sensor in sensors.yaml

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 }}"`
inner mesa
#

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

knotty idol
#

Daily Forecast Template

lapis hound
#

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 }}

inner mesa
#

What is wrong?

marble jackal
#

It doesn't work

opaque sentinel
cosmic hamlet
#

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```
fickle sand
#

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

cosmic hamlet
#

oke. checking that

haughty breach
plain magnetBOT
#

@white lantern I converted your message into a file since it's above 15 lines :+1:

haughty breach
#

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.

white lantern
white lantern
#

I'm a dummy. It needed a data key

haughty breach
#

I was editting above, it's missing data

white lantern
#

data:
target:
etc....

#

Thank you @haughty breach 🙂

#

Interesting - it's not erroring, but it's also not doing anything

haughty breach
#

What are you doing to fire it?

white lantern
#

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
marble jackal
#

I guess you want

target: 
  entity_id: "{{ repeat.item }}"
white lantern
#

So if I add target it kicks it back saying that extra keys are not allowed

haughty breach
white lantern
#

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.

haughty breach
#

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

white lantern
#

That's perfect -- I'll look up how to do that now

knotty idol
#

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

haughty breach
#

You need to fix the name of the response variable... currently it's: response_variable: weather.get_forecasts

knotty idol
#

daily_forecast

haughty breach
#

Yes... response_variable: daily_forecast

knotty idol
#

Alexa just spit out a bunch of errors for entities

haughty breach
#

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.

knotty idol
#

is there a site we can send a video of my alexa issue for troubleshooting?

knotty idol