#templates-archived

1 messages · Page 105 of 1

lapis quarry
#

bummer...

deft timber
#

oh didn't know that

mighty ledge
#

there are ways around it

#

gimme a sec

#
automation:
- alias: Update My template sensor
  mode: parallel
  trigger:
  - platform: event
    event_type: state_changed
  condition:
  - condition: template
    value_template: "{{ trigger.event.data.new_state.domain == 'timer' }}"
  action:
  - service: homeassistant.update_entity
    entity_id: sensor.latest_timer
#

then just make a sensor.latest_timer senosr

deft timber
#

It's a much better solution for your problem Allenbell3d. No need this sensor.latest_timer then. Juste create an automation on the event state_changed, in the condition verify the domain and the status (idle or active) and that's it

brisk temple
#

thanks petro, worked for my case

lapis quarry
#

makes sense

mighty ledge
#

@lapis quarry in your case you could just alter that automation to fit your automation

brisk temple
#

that's a 2 for 1, you can take the rest of the day off

mighty ledge
#

@lapis quarry change the condition to

  - condition: template
    value_template: >
      {% set new_ state = trigger.event.data.new_state %}
      {{ new_state.domain == 'timer' and new_state.object_id.startswith('keyring') }}"
#

Your action will change to:

- service: >
    input_boolean.turn_{{ 'on' if trigger.event.data.new_state.state == 'active' else 'off' }}
  data:
    entity_id: >
      input_boolean.block_{{ trigger.event.data.new_state.object_id }}
lapis quarry
#

ok let me try

#

[homeassistant.util.yaml.loader] while scanning a simple key
in "/config/automations/Keyrings Safety Timer Trigger.yaml", line 166, column 9
could not find expected ':'

mighty ledge
#

Your action has the wrong indentation. service should be in line with data. Also you no longer need to specify service_template. Both service and data do not need to be changed to _template in 0.115+

lapis quarry
#

gotcha

#

but it doesnt seem to trigger

mighty ledge
#

are there errors in the logs?

lapis quarry
#

no, its loading fine

mighty ledge
#

why do you have initial_state off

lapis quarry
#

because I save the timer state on HA restart so I can restore its state after HA has finished booting, I have this automation off and enable it 20 seconds after HA boots so i have gave it time to restore the timers

#

but i have made sure to enable it before testing that is not the reason

mighty ledge
#

subscribe to the state changed event and verify that they are being seen

#

if they aren't being seen, then you don't have a state that changed

lapis quarry
#

yes I can see the event fire

#

although a few other events fire in succession after the timer event (timer save etc)

mighty ledge
#

it should still turn on your input_boolean

#

when it fires are there errors in the logs?

lapis quarry
#

none

mighty ledge
#

Ok, then your input_boolean should be off

#

based on that event change

lapis quarry
#

correct, but its not changing

mighty ledge
#

is the input boolean on?

lapis quarry
#

yes, have tried with both states in the timer idle and active

#

and the boolean on and off

#

does not work either way

mighty ledge
#

whats the name of the input boolean?

lapis quarry
#

input_boolean.block_keyring0xx

mighty ledge
#

should be working based on all that information, otherwise there should be errors in your logs

lapis quarry
#

yes, I see how it makes sense, but its not working and I´m getting no errors

#

automation is not even firing so its not the action portion

#

im asuming the condition doesnt pass for some reason

mighty ledge
#

well, seems like the condition is blocking it. I set this up and it works on my end:

- condition: template
  value_template: >
    {{ trigger.event.data.new_state.entity_id.startswith('timer.keyring') }}
lapis quarry
#

found the problem

#

there was a typo, the extra " at the end of the condition template

#

now it seems to be working 😄

#

Very helpfull Petro!!! Its a very elegant solution, I like it, a lot simpler than what we where trying to do 😎

#

I think im actually gonna use this in many places

mighty ledge
#

@lapis quarry it's a good solution, but keep in mind that it may bog your system down if you have a lot of state changes.

lapis quarry
#

I was wondering about that, will test and see how it goes

slim holly
#

Hello, can anybody tell me whats wrong with this code ? I get only "unknown error" in Homeassistant template-editor.

{% set flur_abs , carport_abs = states('sensor.flur_absolutehumidity') | float, states('sensor.carport_hinten_absolutehumidity') %}
{% if flur_abs >= carport_abs %}
'0'
{%- else %}
'1'
{% endif %}

dreamy sinew
#

use 2 set statements

#

or you need to tuple your states calls

#
{{ foo }}
{{ bar }}```
slim holly
#

Hmm, this is working, the only thing i changed is the comparison == is ok but >=, <=, <, > are not working

{% set flur_abs , carport_abs = states('sensor.flur_absolutehumidity') | float, states('sensor.carport_hinten_absolutehumidity') %}

{% if flur_abs == carport_abs %}
'0'
{%- else %}
'1'
{% endif %}

dreamy sinew
slim holly
#

Ahh, ok i found the problem i missed the second float statement

lapis quarry
fossil bone
#

Is it possible make a sensor that takes the current value of another sensor and compares it with the state of the same sensor a day back in time? I want to see if the no. of registered Covid19-infections has gotten higher compared to a day ago and also for the sensor to show the difference .

wintry moon
#

Hi guys

#

I have a complicated math to be done regarding heating... and I don't know if I should either calculate it in sensor.template or in automation. It contains 6 entities, but when I test it in "templates editor" in HA, HA shows that it's subscribed only to 2 entities. Those 2 are in first "if" of that template... And I'd like to calculate it no matter which IF it passes or not - https://pastebin.com/cF3qf8Dt - latest 0.116.2

inner mesa
#

As I mentioned in the other channel, it won't listen for changes to entities that won't affect the result of the template

wintry moon
#

yeah, I get it now. sensor.time seems reasonable... it's for calculating heating curve, so quite crucial to have all ingredients refreshed every time 🙂

inner mesa
#

you can use that, but like I said, it's trying to be smart about what to listen for because it won't affect the result

#

if you have "x and y" and "x" is false, then listening for "y" is not helpful, for instance

#

until "x" changes

wintry moon
#

but... if sensor template will be
if x
elif y
eiff z
endif
and here some.other.sensors
will it listen to 'some.other.sensors'?

#

or just stop after first if passes?

inner mesa
#

read through that thread

#

it's only going to listen for things that will change the result, and that list can change based on other changes

#

Aside from the possibility that there are bugs, it should just work

#

and to a certain degree, adding that information in the template tester is just causing more confusion, rather than helping you make better decisions

wintry moon
#

it's just a calculation I'd like to have accurately set between some hours

inner mesa
#

is it not working?

wintry moon
#

I have feeling it's 'delayed', as one of it's sensors is outside temperature and while it changes, the calculation is not refreshed (or it's just a feeling, will test it with new knowledge)

#

or it may be just lost with rounding too

inner mesa
#

I would recommend reporting an issue if you can identify one, but not preemptively

wintry moon
#

right

#

will do, thanks. 🙂

lapis quarry
#

Can somebody help me with this?

I have this template condition: {{ is_state('group.room01', 'home') }}

and this: {{ states.switch.airconbr01a.entity_id[-3:-1] }}

Trying to combine both to do something like this: ```"{{ is_state('group.room(states.switch.airconbr01a.entity_id[-3:-1])', 'home') }}"


Trying to get it to work in the template editor, its not giving any errors but it allways rendering false
#

want to carry the number 01 from the switch to the template

white burrow
#

Could someone help me with this easy one. I tried looking into YAML and getting variables in commands.

I have a password stored in secrets.yaml. Lets say password: somepassword

How could I get that in shell_command?
For example:
www.somesite.com/login.php?username=username&password=XXXXXX
and have the password pulled from secrets.yaml. I tried putting {{!secret somepassword}} but obviously thats not right formatting.

heavy ember
#

the idea of the secrets file is to remove the passwords from your configuration for backup / storage and security. AFAIK you cant pull that password to be used in something like a shell command. They are just to remove them from your configuration files. Happily be proven wrong but that is my understanding

#

otherwise malicious payloads or addons could attempt to expose all of your passwords

#

as you could imagine, some dodgy python code could be brute-forcing '!secret stringhere' in the background and pushing them off to some other site/api. There isnt a secure module to authenticate and authorise users or addons to specific passwords

white burrow
#

I get that. But currently only way I can get my ptz cameras to turn is to use shell command to run curl with my ipcams password as a plain text

#

not sure having it pulled from secrets.yaml would make any difference

heavy ember
#

exactly, it isnt providing any extra security. If someone can read the shell command file/configuration.yaml then they can read secrets.yaml

white burrow
#

well I ended up adding the whole shell_command variable in the secret.yaml 🤷‍♂️ so rather than trying to get the username/password pulled from secrets.yaml I added the curl command itself in there.

silent barnBOT
umbral bridge
#

Could someone help me to figure out why this automation can't trigger. Above me is the Automation code and the Event data will follow this message.

silent barnBOT
coarse tiger
#

@umbral bridge

silent barnBOT
umbral bridge
#

Apologies it just started working suddenly.

#

Nvm no it didn't. Was confused of a similiar automation that triggered.

rugged laurel
#

That template will always be false

violet oyster
#

oh really? i was testing it with != since i do have an id

#

ill delete the answer i guess ha

rugged laurel
#

You did a compare with strings on both sides (both sides was quoted), because of that a would never match b

violet oyster
#

oh

#

so just the null should be a string then

#

nah still doesnt work

rugged laurel
#

== None

violet oyster
#

yep that sure works

#

@umbral bridge

{{ trigger.event.data.new_state.context.user_id == None  }} 
umbral bridge
#

Thank you @rugged laurel and @violet oyster ! It worked!

lapis quarry
#

Guys, quick question: is there any way to set a variable in a template and use it throughout the automation it has been set in?

#

Doing this:
{%- set xxx = xxx %}
I need to use it in a bunch of different conditions inside the same automation and have to redo it inside every condition.

violet oyster
#

you could just make a template sensor and refer to it in the automation as many times as you want. thats what I do.

#

as I undertand it the entire automation would have to be a single template to preserve the variable, which isn't possible since the automation needs to be in yaml.

#

you could also use input_text instead of a template sensor. the first action sets the input text then the rest of the actions refer to it

#

@lapis quarry

lapis quarry
#

I see, thanks barbados, but I think my use case that would not work

rugged laurel
#

Create a script where you use a variable to do stuff.
Call that script an pass in the variable form the automation action

violet oyster
#

@rugged laurel always has better ideas than me

lapis quarry
#

dont think it would work either for what im trying to write..

rugged laurel
#

It will

violet oyster
#

what are you trying to do??

lapis quarry
#

this, and now I need to add a bunch of other sequences which will also use the same variables

violet oyster
#

what is this supposed to achieve?

#

honestly it seems needlessly complex. why set variables based on the state change data instead of just refer to the state change data in the action or condition itself?

lapis quarry
#

not sure I follow your question, I have a use case where I want the same automation to work in different scenarios with different amount of sensors and switches, so I can expand and just add more sensors or switches and want it to be transparent to the automation

#

dont want to define the entity ids of anything manually inside the automation

#

its a little complex but this does what I want pretty much

#

anyway, no issue I will just define the variables inside every condition its no big problem

lapis quarry
#

Could anyone give me a pointer on how I could replace the XX in this statement by another variable called room_number?

{%- set ts_delta = (as_timestamp(now()) - as_timestamp(states.group.roomXX.last_changed))|round %}

#

🤔

thorny snow
#
      friendly_name: "Bad varmekabel"
      unit_of_measurement: "W"
      value_template: >-
        {% if state_attr('climate.bad_varmekabel','current_temperature') > state_attr('climate.bad_varmekabel','temperature') %}
          0.0
        {% else %}
          1170.0
        {% endif %}
      icon_template: mdi:speedometer``` Any idea why this one gives me errors and returns unknown? It works in the template editor.
inner mesa
#

Errors?

silent barnBOT
#

Rule #6: Please do not post codewalls (longer than 15 lines) - use sites such as https://hasteb.in/, https://paste.ubuntu.com/, or others.

Please take the time now to review all of the rules and references in #rules.

inner mesa
#

Try configuration > Server Controls > Reload template entities

thorny snow
#

ok, then it works. Is there a way to delay that template loading on reboot?

inner mesa
#

I’ve seen a lot of folks with this issue lately. You should be able to call ‘homeassistant.update_entity’ on it, but I recommend searching/filing an issue about it

silent barnBOT
inner mesa
#

Are these sensors from MQTT?

thorny snow
#

nope, z-wave

#

ozw

inner mesa
#

Ok. Check if there’s a backend issue and maybe file one. May also be helpful to see if there’s a relevant forum thread

#

Changes were made recently to optimize template listeners and there may be an issue

#

OZW uses MQTT, BTW

#

the beta at least

thorny snow
#

yeah ok, maybe i'm worng. i'm using the default built-in version, haven't moved to the z-wave2mqtt yet

inner mesa
#

Ok, then not MQTT

#

They’re both OZW, just different versions and use different mechanisms

#

Same advice

lapis quarry
#

Can somebody point me in the right direction on how I can do this? cant seem to figure out how I should format it #templates-archived message

inner mesa
#

for what exactly? using variables in scripts?

lapis quarry
#

Want to replace XX with the value in room_number

                  {%- set room_number = trigger.event.data.new_state.object_id[-3:-1] -%}
                  {%- set ts_delta = (as_timestamp(now()) - as_timestamp(states.group.roomXX.last_changed))|round %}

Or replace the full roomXX also would work

#

for what exactly? using variables in scripts?
@inner mesa yes

lapis quarry
#

its actually not in a script, its inside in a automation I´m writing

inner mesa
#

an automation can call a script

lapis quarry
#

I´m really quite a newby, just started playing with templates, cant picture how a script is going to sort the problem 😅

#

but if I can just figure out how to format the above it will do what I want..

#

trying this but I guess its makes no sense because im asuming it outputs a string: "(as_timestamp(now()) - as_timestamp(states.group.room" ~ '{}{}'.format(room_number,".last_changed)

#

also been playing around with the replace command but no luck either..

inner mesa
#

looks like you can do something like this to get "last_changed" with an entity constructed from a variable:

#

{{ states.switch['fr_' + var + '_lamp'].last_changed }}

#

in your case:

#

{{ states.group['room' + room_number].last_changed }} or similar

lapis quarry
#

let me try

#

awesome Rob, that seems work in the template editor {{ as_timestamp(states.group['room' + room_number].last_changed) }}

inner mesa
#

had to dig up the syntax from the forum, but it makes sense

lapis quarry
#

what do the [] do?

inner mesa
#

indexes into dict of items in a particular domain

#

and returns the object for the entity based on the name that you constructed and passed in

lapis quarry
#

amazing, just tested the automation and it also works 😄

#

Thanks Rob, appreciate it, spent a few hr trying random stuff 😅

inner mesa
#

np, glad it's working

ionic hazel
inner mesa
#

looks okay to me, other than data_template: should be data:

ionic hazel
#

oh sweet

inner mesa
#

does it not work?

ionic hazel
#

i gotta ton of red lines in VS Code, so i didnt actually check config yet. This is my first template

#

and swapped out his denon with mine

inner mesa
#

and the red lines in VS Code are related to that?

ionic hazel
#

I think so. I noticed in his post his the hypen is right under the switch, where in my yaml i have a space before the hyphen. I just tried to show it here, but my formattin looked god awful

inner mesa
#

2 spaces or no spaces is okay as long as you're consistent. 1 space is not

ionic hazel
#

ohhhh.

#

sweet

#

Okay okay in my yaml it's 2 spaces everytime

#

Other than that just chagne data_template to data ?

inner mesa
#

you should do that, yes

#

if I paste that right into my configuration.yaml, VSCode is fine with it

ionic hazel
#

Did you have 2 spaces or 0?

inner mesa
#

I pasted what you posted

ionic hazel
#

Gotcha. I got no red lines now, lets see how it goes

inner mesa
#

you didn't change data_template: to data:, but I expect so

ionic hazel
#

ahh dangit

inner mesa
#

try it?

ionic hazel
#

Trying now

tight parrot
#

Anyone have ideas why I'm not able to reference sensor.current_version anymore? I'm seeing unknown rendered in in the following template (part of a mobile notification):

    title: 'Update for Core available'
    message: "New version is {{ state_attr('binary_sensor.updater', 'newest_version') }}. Currently on {{ states('sensor.current_version') }}"
#

Looks like my sensor.current_version entity is missing, but I don't recall deleting it recently - was there a recent change that would have caused this?

inner mesa
#

it's not a standard thing

tight parrot
#

well, poop

ionic hazel
#

It worked! Thanks, Rob!!!

inner mesa
tight parrot
inner mesa
#

probably from the integration that I pointed to

tight parrot
#

perhaps, it's not mentioned in that thread from what I can find, though

inner mesa
#

or as an attribute for sensor.supervisor_updates

tight parrot
inner mesa
#

so you have what you need?

tight parrot
#

yeah, I'm good, thanks

frail star
#

Hi, i make a template binary_sensor {{ (now().astimezone().tzinfo)| string == 'IDT'}} . when ha start to run the binary_sensor update with correct data but when i changed it manually he didn't update him self.

#

any idea ?

#

now() is not update every minute ?

bitter atlas
#

@frail star templates update based on the entities used within them. now() does not trigger that. which is why it works once upon restart and never again thereafter

frail star
#

but sensor.date didn't have tzinfo

#

so how can i get the correct timezone change ?

bitter atlas
#

@frail star There are others who can probably give you better options but you can always update the entity through automation with homeassistant.update_entity service

frail star
#

i try this one to: '{{ states("sensor.date_time") and (now().astimezone().tzinfo)| string == "IDT" }}'

bitter atlas
#

that will work too

frail star
#

but also didn't work

bitter atlas
#

try states('sensor.date_time_iso')

frail star
#

not working

bitter atlas
#

well like i said you can always update it through an automation

steep kiln
#

could someone ELI5 when to use an automation to update template sensors and when not? got a bunch linked to sensor.date_time and just deleted the the entity_id option in the sensor definition

timid radish
#

hi! is there a way to change icons in the lovelace template for climate? function for cooling shows heating

gusty nimbus
#

i have an sensor.gas_verbruik (translated sensor for gas usage for the heater and cooking) but its not an per day thing it just the total gas usage that keeps going up

#

i have this in configuration.yaml

sensor:
- platform: rest
  resource: http://mylocalip/api/v1/smartmeter?limit=1&json=object&round=off
  name: Gas verbruik
  value_template: '{{ value_json.0.CONSUMPTION_GAS_M3 }}'
  unit_of_measurement: "m³"

Anyone an idea how to create a Gas per day thing? many thanks on advance

little gale
#

A input_number goes from 70 to 100. How do I create a template light from it that works in HomeKit?

gusty nimbus
#

it could work with something that calculates it but i don't know how 😉

little gale
#

@gusty nimbus you may want to look into History Stats

violet oyster
#

@gusty nimbus i was about to say that too but idk if that does math, just counts time. like how much time was the entity a certain state

gusty nimbus
#

@little gale i can click on the stats yes and calculate in my own head yes 🙂

violet oyster
#

that sensor outputs an integer right?

little gale
gusty nimbus
#

i think i should need something like it uses the latest number at 12O clock mid night and from then count it to have per day? 🙂

violet oyster
#

@little gale i just saw that, would 'count' work for this? there doesn't seem to be an explanation of what that does

#

oh yeah there is

#

that doesnt look like it would work

gusty nimbus
#

i want to make an other sensor for per day

#

how and what could i set ? 🙂

#

im not very good in this things :p

violet oyster
#

@gusty nimbus yeah what I would do is set an input number at 12:01 based on the state of the sensor, then set another one that night at 12:00. then use another automation to compare the two and set a third input number, which would be the amount used that day.

#

then you could expand that to have one for each day of the week, or whatever you want

#

and make template sensors to read out stats. like average, total this week, etc

little gale
gusty nimbus
#

hm ok

little gale
#

Has all those

violet oyster
#

yeah statistics integration could definitely make it easier

gusty nimbus
#

and change max_age to 24 hours ?

little gale
#

yep

#

hours: 24

gusty nimbus
#

hm ok i start to understand i think

little gale
#

You could make a template sensor to extract total

gusty nimbus
#
sensor:
  - platform: statistics
    entity_id: sensor.gas_verbruik
  - platform: statistics
    entity_id: sensor.gasusageperday
    max_age:
      hours: 24
#

something like this?

little gale
#

its a binary sensor?

violet oyster
#

no he just copied the example i think

little gale
#

oh

gusty nimbus
#

yes i copyed and changed 🙂

violet oyster
#

the entity_id would be the id of your rest sensor

#

then set name: to name your new stats sensor

gusty nimbus
#

rest sensor means the one i allread had that keeps on counting up ? 🙂

#

oh ok

#

i edited

violet oyster
#

you only need one, with max age 24

gusty nimbus
#

and do i have to get it resetted at 12PM ?

violet oyster
#

the statistics sensor will show a rolling average of the last 24 hours at any point in time

gusty nimbus
#

oh ok

#

so if i set this up at 13:42 like its here now it will count till tommorow same hour

violet oyster
#

if you want it to be per calendar day, youd have to go with my original idea of the input numbers

#

yes. and then at 13:42 tomorrow it would just be a rolling, continuous count of the past 24 hours

gusty nimbus
#

or i find a way to manual reset it this night at 00;00 my self? :p

violet oyster
#

unless you have the recorder set up, in which case it would start working right now

#

you could purge the recorder each night but that would mess up your history and logbook

#

and if you did that the number would only be meaningful once per day, at midnight

#

and i'm not even sure that would work. might need to reload the statistics integration as well which there isn't an easy way to do

#

so the input number might be the better idea for your use case

#

@little gale what do you mean by making a template light from an input number? like using the number for the brightness?

little gale
#

Yep

#

There's math involved that I can't quite chalk out

violet oyster
#

somebody asked something similar the other day. Templates can't return numbers only strings. so they can't be used in the brightness field of the light.turn_on service. some integrations have another service to set the brightness but none of the ones i've used do

#

you could use a bunch of scripts and automations and stuff to set it manually, and then in your template light template which script it would call based on the state of the input number

gusty nimbus
#

@violet oyster
so i think the best way the input numbers?

violet oyster
#

if you want it to be per day, then yes. in my opinion at least.

gusty nimbus
#

oh ok

#

you have some example? 🙂

violet oyster
#

are you using yaml?

gusty nimbus
#

yep

violet oyster
#

give me a minute

gusty nimbus
#

sure you could have more to don't rush many thanks on advance

violet oyster
#

alright this isnt gonna work but i have another idea. stand by

thorny snow
#

I have a value_template "{{((states('input_datetime.android_alarm')|as_timestamp|int - now()|as_timestamp|int)/60)|int == 15 }}" and it comes up "true" as expected. but for some reason i cant get it to trigger an automation? whats up with that?

fossil venture
#

now() is a function. It won't trigger automations.

#

Create and use sensor.time instead.

violet oyster
gusty nimbus
#

ok tx sec

violet oyster
#

should work immediately but let me know if it doesn't

gusty nimbus
#

input_number:
where to put that in configuration.yaml ?

#

the automation part in automations.yaml i think

violet oyster
#

either make it a package or copy each part to the correct area

gusty nimbus
#

oh i get it

violet oyster
#

(packages make stuff like this much easier)

gusty nimbus
#

yes i know i still have to do that 😉

#

maybe a question

#

gas_at_1159:

#

here the timezone is like in the 24 numbers

violet oyster
#

oh yeah my bad

gusty nimbus
#

so gas_at_2359 ?

violet oyster
#

should be 2339

#

2359*

gusty nimbus
#

ok good 🙂

#

np 😉

violet oyster
#

it works the same here too i just had a brain fart lol

gusty nimbus
#

lol np 😉

#

maybe a stupid question if i put that in for example gasdayusage.yaml

#

and load that up

#

i think it will break with the other sensor things in configuration.yaml ?

#

duplicated things 😉

violet oyster
#

no, as long as packages: is configured in configuration.yaml

#

keys in packages don't conflict with keys in configuration.yaml

gusty nimbus
#

oh ok

#

i will try that 😉

#

then if it works its later on a good time to put it all on seporated things :p

violet oyster
#

you could expand on what I did if you want more than one day. make extra automations and input numbers for

#

gas 2 days ago, gas 3 days ago, etc

gusty nimbus
#

yes idd

#

week & month 😉

violet oyster
#

i'd say the statistics integration would be better for that since you won't need precise numbers. but it could be done with my method as well

gusty nimbus
#
homeassistant:
  packages: !include_dir_named gas
violet oyster
#

although again, if you want actual months instead of just 'past 30 days' then yeah

gusty nimbus
#

then i could make a gasperday.yaml inside the dir gas ?

#

🙂

#

oh ok 🙂

violet oyster
#

i would just do a folder named packages then make gas.yaml

gusty nimbus
#

oki 🙂

#

and if i make changes in the gas.yaml in the packages folder do i still need to restart full HA for the changes ?

#

btw many thanks for all the effords 😉

violet oyster
#

its my pleasure. you don't need to restart HA, you can just use the reload functions in configuration > server controls to reload each type of thing. automations for automations, input numbers for input numbers, template entities for template sensors and whatnot

#

assuming you are using HA and not HA core

gusty nimbus
#

oh nice

#

btw

  - alias: set gas yesterday
    trigger:    
      platform: time
      at: '12:00:00'
violet oyster
#

just make sure to reload the dependencies first. input numbers then sensors then automations

gusty nimbus
#

does it have to be 00:00:00 ?

violet oyster
#

yep lol

gusty nimbus
#

ok great 🙂

#

input_number:
gas_at_0001:

#

the beginning was correct

#

:p

violet oyster
#

lol im tired

gusty nimbus
#

np 🙂

#

i think i changed all correct

violet oyster
#

good catch though. would have been frustrating if it didnt work because of that

gusty nimbus
#

idd 🙂

violet oyster
#

that looks good to me

gusty nimbus
#

gonne restart HA because i didn't had that packages rule 🙂

violet oyster
#

you can test it by manually triggering all 3 automations in developer tools > states

gusty nimbus
#

just to make sure its fine 😉

violet oyster
#

yeah youll need to restart to get packages working the first time

gusty nimbus
#

ok its busy
HA isn't very easy to start but i played for like 7months without any education

#

thats why maybe i ask stupid things 😉

violet oyster
#

honestly for someone who is new to it you understand it very well. i've given up on people many times

gusty nimbus
#

im not a guru like most people here :p

#

i never give up 😉

violet oyster
#

i'm not either, i've just been using it a few years

gusty nimbus
#

i have an digital electrical meter & gas i have another rpi doing the readings 😉

#

but gas per day wasn't supported

#

nice

violet oyster
#

i'm just good at finding workarounds haha. i don't know how things actually work

gusty nimbus
#

im an Linux user for like 20Y but this kind of scripting code automations in yaml is something else then i mostly do 😉

#

nice 🙂

violet oyster
#

i just switched to linux full time actually. previously i only used it on my server

#

ubuntu 20.04

gusty nimbus
#

ok i found the sensor.gas_yesterday

#

a sensor gas today wasn't possible i think?

violet oyster
#

good, now manually execute the automations in order, make sure the set_gas_yesterday one is executed last

gusty nimbus
#

ok gonne try

violet oyster
#

the sensor should go to 0

#

you want a sensor to show you how much gas you've used so far today?

#

that is possible

gusty nimbus
#

yes

#

i went to dev tools and didn't changed the on to off it just leaved it on

#

and hit define states

#

(or how its called in english)

#

i did the first 2 and then the yestoday

#

but it stays on 0 in my example

violet oyster
#

it should be 0

gusty nimbus
#

its 0 yes

violet oyster
#

since both numbers were set right now

gusty nimbus
#

gas_yesterday
8 minuten geleden

violet oyster
#
sensor:
  - platform: template
    sensors:
      gas_today:
        value_template: "{{  (states('sensor.gas_verbruik')|float) - (states('input_number.gas_at_0001')|float) |round(2)}}"
        unit_of_measurement: "m³"  
gusty nimbus
#

8 minutes ago 😉

violet oyster
#

that should give you gas so far today, once input_number.gas_at_0001 is set

#

none of these will be accurate until after 00:01

gusty nimbus
#

ok this i have set now

#
sensor:
  - platform: template
    sensors:
      gas_today:
        value_template: "{{  (states('sensor.gas_verbruik')|float) - (states('input_number.gas_at_0001')|float) |round(2)}}"
        unit_of_measurement: "m³"  

  - platform: template
    sensors:
      gas_yesterday:
        value_template: "{{ states('input_number.gas_yesterday')|float |round(2)}}"
        unit_of_measurement: "m³"
violet oyster
#

you don't need the

  - platform: template
    sensors:
#

on the second one

#

but it won't hurt.

#

reload template entities and it should work

gusty nimbus
#

oh ok

#

Nice it works

violet oyster
#

great

#

now wait a day and you'll get real numbers

#

also the |round filter, i just randomly chose 2 decimal places. you could make it whatever you want

#

not sure what the value from your rest sensor looks like

gusty nimbus
#

gonne show you

#

gas_today
3 minuten geleden
0.0030000000000001137 m³

#

3 minutes ago 😉

violet oyster
#

what about sensor.gas_verbruik

gusty nimbus
#

sec

#

Gas verbruik
17 minuten geleden
39.493 m³

violet oyster
#

i guess it would depend how much it changes

#

if you only use 0.00004 m³ of gas per day then you'd want |round(5) at least. know what I mean?

gusty nimbus
#

yeah i understand

#

but it will be alot higher 😉

#

its not heating atm 😉

#

does it update on its self the gas daily?

#

gas today?

violet oyster
#

the sensors should update whenever the states of the references entities change

gusty nimbus
#

oh ok

violet oyster
#

so gas_yesterday should only update once per day while gas_today should update whenever sensor.gas_verbruik updates

#

dutch is way cooler than english btw

gusty nimbus
#

you speak english? or dutch to ? 🙂

violet oyster
#

just english, I googled 'verbruik' lol

gusty nimbus
#

oh ok 🙂

#

sorry 🙂

violet oyster
#

i'm just a dumb american who only speaks one language

gusty nimbus
#

lol 🙂

#

dumb i would not say 🙂

#

here in Belgium most people speak Dutch, french , german , english

#

french i don't know alot things 😉

violet oyster
#

that's too many languages. you guys should make up a belgian language

gusty nimbus
#

dutch german( understand most) and english is good 🙂

#

we have dialects to 😉

violet oyster
#

yeah your english is great. that's the hardest thing about helping people in here in the morning

#

i work nights so most of the people on here are in europe when I get on

gusty nimbus
#

i make many faults in english but most i learned on my self 🙂

#

yes thats true another timezone

#

there its 15:04 now 🙂

violet oyster
#

09:06 here

gusty nimbus
#

oh just out of bed? 🙂

violet oyster
#

no, just got off work

gusty nimbus
#

oh ok enjoy your work there

#

its sunday here 😉

#

and many many thanks !!!

violet oyster
#

no problem. send me a direct message if you need any more help

gusty nimbus
#

ok you to 😉 tx see ya later

rain cove
#

What domain (sensor, switch, automation, etc) would I use for a template that represent toggling on/off all automations?

#

Basically a toggle that allows easily pausing automations

coarse tiger
#

Basically a toggle that allows easily pausing automations
@rain cove make a group with your automations in it and toggle the group

rain cove
#

Im avoiding creating a list of automations, as keeping that up to date will suck. I am calling the service automation.turn_off with the entity id all

#

I just don't know what the template should be included under in configuration.yml

#

Is it a switch? My light template is under lights which make sense

coarse tiger
#

i get the entity: all part but i don't know what you mean by template. just trigger the service?

rain cove
coarse tiger
#

just include this automation as entity

rain cove
#

I don't know what you mean

inner mesa
#

a template switch would work

rain cove
#

Ok. Should I move my "all lights" switch there too? I made it as a light because I thought it had to be

inner mesa
#

"it"?

#

I'm just talking about your request to enable/disable automations

rain cove
#

Sorry... its a template that represents all entities of the light domain so I can turn them all on and off together

inner mesa
#

you could

rain cove
#

Thanks Rob

inner mesa
#

np

bitter atlas
#

there is a light group that you can clump as many lights into as you want and control all of them at once without needing to make some template

rain cove
#

That would require creating a group however

ruby vault
#

any thoughts?

fierce hornet
#

How can I create a sensor that display's the name of the month (or first 3-4 letters of it) based on the sensor.date sensor? Does anyone happen to have a template for that?

inner mesa
#
{% set months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] %}
{{ months[now().month-1] }}
#

Probably an easier way

#

lol

#
{{ now().strftime("%b") }}
fierce hornet
#

Thank you! Will be using the first method I think so I can change them to my own language, second one display's in English.

inner mesa
#

it's supposed to convert to the local lang

#

YMMV

#

easy enough to try in devtools -> Templates

fierce hornet
#

Wait, got confused. it probably does but oct is the same it both languages😅 woops

#

Wait, got confused. it probably does but oct is the same it both languages😅 woops
Although, the full month version (so %B) doesn't seem to get translated.

oblique cloud
#

I have an automation with 7 input_datetime trigger (week day).
In the condition, i have an if statement for each day.
How can I know which datetime was triggered?

blazing burrow
#

probably trigger.event.something

elfin bluff
#

is there a (slider)control that allows you to set a min and max scale? Say the range is 1 to 100 and in the control you slide the min dot to 25 and the max dot to 50?

lapis quarry
#

hey guys I have this for loop that list a series of sensors:

{% for x in states.binary_sensor 
    if ( 'windowbr' in x.object_id and room_number in x.object_id and 'batt' not in x.object_id and x.state == 'on' ) 
    or ( 'doorbr' in x.object_id and room_number in x.object_id and 'batt' not in x.object_id and x.state == 'on' ) %} 
{{ x.name }} 
{%- endfor %}

From the entities that this loop prints I would like to figure out which one is the one that has been more time in the state "on" and output its time stamp

#

how could I go about doing that?

deft timber
#

I think that the only way to know how many time a sensor has been in a given state is by using stat sensor, but you will have to create 1 by sensor

lapis quarry
#

using last_changed I get the time stamp of the last time it changed state

#

I just want to sort trough that and get the one that is lower (oldest one)

#

trying this:

#
{%-for x in states.binary_sensor 
    if ( 'windowbr' in x.object_id and room_number in x.object_id and 'batt' not in x.object_id and x.state == 'on' ) 
    or ( 'doorbr' in x.object_id and room_number in x.object_id and 'batt' not in x.object_id and x.state == 'on' ) %} 
{{ x.name }} {{ as_timestamp(x.last_changed)| timestamp_custom('%H:%M:%S') }}
{%-set ns.time = ns.time ~ '{},'.format(x.last_changed.timestamp()|int ) -%}
{%- endfor %}

{{ns.time}}
{{ ns.time|min}}```
#

{{ns.time}} contains a list with the time stamps: 1602502161,1602502151,1602502132,1602502140,

#

but {{ ns.time|min}} is outputing 0, wich is the lowest single number in that string wich is not what I need

deft timber
#

{{ns.time.split(",")|min}}

lapis quarry
#

not outputing anything..

deft timber
#

it is because of the ',' at the end

#

{{s.time.split(",")[0:-1]|min}}

muted berry
#

Hi! So I'm trying to make a template to have as a condition to trigger the automation but only between 1st of November until first of April. Is this the correct way to write it? https://pastebin.com/a8s1bG5x

lapis quarry
#

yep, that works

#

👍

deft timber
#

Aleks, what is n ? Use now() instead

muted berry
rugged laurel
#

set ns.time to be a list and not a string

#

that just looks strange

#

and you need added logic to split it

muted berry
#

I don't really have any competence to properly write it

#

as I don't write yaml

rugged laurel
#

this is not yaml 😉

muted berry
#

lol

rugged laurel
#

it's jinja 🎉

muted berry
#

you see?! 😄

deft timber
#

Look a little bit higher in the page: {% set n = now() %}

rugged laurel
#

Change {% set ns = namespace(time = '') %} to {% set ns = namespace(time = []) %}
and {%-set ns.time = ns.time ~ '{},'.format(x.last_changed.timestamp()|int ) -%} to {%-set ns.time = ns.time + [x.last_changed.timestamp()|int] -%}

muted berry
#

Look a little bit higher in the page: {% set n = now() %}
@deft timber not following

deft timber
#

In the link you pasted, in a previous post, n is defined as now(). So either you use now().month as suggested or you define n in your template

muted berry
#

Ohhh, so " value_template: "{{ now().month >= 10 or now().month < 4 }}""

deft timber
#

yep

muted berry
#

Thanks! 😄

lapis quarry
#

Change {% set ns = namespace(time = '') %} to {% set ns = namespace(time = []) %}
and {%-set ns.time = ns.time ~ '{},'.format(x.last_changed.timestamp()|int ) -%} to {%-set ns.time = ns.time + [x.last_changed.timestamp()|int] -%}
@rugged laurel ' ' defines it as a string and [] as a list?

#

makes sense, yes now it works better

storm dawn
#

Is it possible to use a template when customizing a device's friendly name somehow? Like for "XXXXXXX's Echo next Reminder" it'd be cool if I could make the friendly name whatever my reminder is if one actually exists, and default back to that if one does not... Though putting a template in the customize UI didn't seem to do anything

dreamy sinew
#

appending to a list is a pain in the jinja env we use

#
...
{% set ns.time = ns.time + [new_timestamp] %}
...
{{ ns.time|min }}```
peak juniper
#

Trying to add to decimals together, testing out with template editor but it keeps putting it from 0.41 to 0.0

#
value_template: "{{  states('sensor.washingmachinecost_today')| float  | round(2) }}"
#

when I get rid of float it works obviously, but I'm trying to add two values together and not sure how to bind them together properly without it being text-like

#

I'm wondering if because my sensor is "£0.42" it doesn't work properly because the £ is throwing up problems?

buoyant pine
#

Yes, that is exactly the reason

peak juniper
#

awesome - I'll have to play around with my sensor then

#

unit of measurement creates a suffix rather than a prefix doesn't it?

buoyant pine
#
value_template: "{{ states('sensor.washingmachinecost_today').replace('£','') | float | round(2) }}"
#

Wait. Does the actual state of the sensor show the £

peak juniper
#

this is my template sensor:

value_template: '{{ "£""%.2f" | format(((state_attr("switch.washing_machine", "today_energy_kwh")) | float) * (states.input_text.energycost.state|float)/100) }}'
#

Changing to the following gives me a numerical value but I'd like to have the £ on there for the frontend without having to create a second sensor:

value_template: '{{ (((state_attr("switch.washing_machine", "today_energy_kwh")) | float) * (states.input_text.energycost.state|float)/100)|round(2)  }}'
keen hedge
#

Good evening Guys. I was wondering how to turn this value 57848178 (for example) into this : 57.848.178 ? ( the comma is the point where i live)

#

(DECIMAL POINT IS COMMA Old people will know 🙂 )

#

haha i found out by myself.... just used the wrong formatting rule

#

for the interested:

#

{{ "{0:,.0f}".format(states.sensor.starman_distance.state | int) }}

torn meteor
#

real quick, unique_id string (optional) -- does this require a machine name or human name? "my_ac" or "My AC"?

torn meteor
#

nevermind.

#

how to I cast a string to an entity though?

#

something like {{ this.gives_me.an_entity_id }}.attributes.current_temperature

inner mesa
#

you mean a variable?

torn meteor
#

well i have sensor A that returns an entity_id - as a string, i guess

#

sensor B needs to use sensor A's attribute value

#

i can usually feed services and entity_id by calling {{ states.input_text.current_ac.state }} and it works

#

so if that template gives me climate.ac_1, how can I get that devices attribute values?

#

oh.. maybe i should just add the attribute i want directly onto sensor A

#

?

#

basically it's nested evals i'm looking for: {{ {{ state.input_text.entity_id}}.attributes.my_attr }}

#

GOT IT: {{ state_attr(states.input_text.current_ac.state, 'current_temperature') }}

#

since the first arg is a string, we're good

inner mesa
#

right, was just coming to mention that after testing 🙂

#

states('input_text.current_ac') would be better for the interior call

torn meteor
#

prevents a failure, right?

lapis quarry
#

I´m writing this condition :

    trigger:
    - platform: event
      event_type: state_changed
    condition:
      condition: or
      conditions:
        - condition: template
          value_template: >
            {%- set new_state = trigger.event.data.new_state %}
            {%- set old_state = trigger.event.data.old_state %}
            {{ new_state.domain == 'binary_sensor' and new_state.object_id.startswith('window') and old_state.state != 'off' }}
#

I would like it to reject if the object_id is finished in batt

#

would this be correct?

#

and 'batt' not in x.object_id

#

like this: {{ new_state.domain == 'binary_sensor' and new_state.object_id.startswith('window') and 'batt' not in new_state.object_id and old_state.state != 'off' }}

inner mesa
#

that'll reject an object that contains "batt"

#

you may want endswith()

lapis quarry
#

where?

inner mesa
#

just trying to interpret "reject if the object_id is finished in batt"

#

otherwise, I don't know what that means

lapis quarry
#

I have binary sensors named binary_sensor.windowbrXX and binary_sensor.windowbrXXbatt

#

I just want it to pass with the first ones

inner mesa
#

so, not new_state.object_id.endswith('batt')

lapis quarry
#

gotcha 👍

#

and not right?

#

new_state.object_id.startswith('window') and not new_state.object_id.endswith('batt')

#

?

inner mesa
#

looks okay

#

you can create a variable in devtools -> Templates with whatever you want to test with

#

make sure it matches and rejects what you want

#

a regex would probably be more compact, but harder to read

lapis quarry
#

now you lost me 😅

rugged laurel
#

Regex == dark magic

lapis quarry
#

lol I think ill stick with this as I barely understand it as is

inner mesa
#

I tried some stuff and lost interest

lapis quarry
#

you can create a variable in devtools -> Templates with whatever you want to test with
@inner mesa thanks for the tip, hadn´t occurred to me, that worked

ruby vault
dreamy sinew
#

Odd, it might not like that it's doing everything twice

#

Oh, 2 different filters nvm

violet oyster
#

@ruby vault there was a new issue with .115 where template entities that refer to other template entities that appear lower in the yaml config would throw a false template loop error (among other errors). It was fixed in that the entities now will eventually update state once the dependency is loaded, but it still shows the error in the logs. Since both of those sensors refer to the other one (and therefore you won't be able to get them in the correct order), you'll always get that error. You could open an issue about it, or just ignore it. Or maybe somehow reconfigure the templates so that they don't refer to one another.

#

also it kind of is a template loop. since they both refer to themselves. not necessarily a problem after initial loading but it's not surprising that it is being flagged as a loop since it is indeed self-referential. so even if you fix the issue I described before, you might still get an error. Not sure.

ruby vault
#

yeah, ok.... well, that tells me lots

#

and makes more sense now

violet oyster
#

maybe you could set an attribute in the two template sensors and use your reject filter to reject them based on that attribute instead of referencing the entity_id

#

not sure if that would work or not, ive never done anything quite like this. just an idea

lapis quarry
#

I´m trying to write an automation using as a trigger the state_changed event, something in the lines of: https://paste.ubuntu.com/p/5fy2rdyWFN/

Thing is I would like it to trigger X minutes after the state change happened, any ideas on what would be the best way to achieve that?

deft timber
#

just put a delay as the first action

lapis quarry
#

can I check again in the action if the sensor is still on after the delay?

#

its a window sensor, I want it to trigger if the window stays open for more than 10 minutes, if its closed before that time has elapsed I dont want it to execute

deft timber
#

with a choose statement yes

lapis quarry
#

🤔 how?

lapis quarry
#

the delay would go in the action right? and the condition that checks again would need to come before the action, or am i missing something?

deft timber
#

first step of the actions is the delay
second step of the actions is the choose statement to check that the window is still open

lapis quarry
#

You mean:

Delay would go here? 
      - choose:
          - conditions:```
#
    action:
      - delay: '00:10:00'
      - choose:
          - conditions:
#

like this ?

deft timber
#

yep

#

the only problem here is that if you window is closed and then reopened within the 10 minutes, your action will be triggered as well

lapis quarry
#

you mean the delay would restart counting again 10 minutes in this case?

deft timber
#

Yes and no. The reopening will trigger again an event so your automation will be triggered a second time, but your first automation will still be in the delay step, and after the 10 minutes of the first automation will execute whatever you want to launch in your automation

lapis quarry
#

can I set mode: restart to sort that ?

#

🤔

deft timber
#

it could work I guess

lapis quarry
#

ok ill give it a try 🙂

#

just realized one thing, i´m referencing the trigger event in the action: {%- set room_number = trigger.event.data.new_state.object_id[-3:-1] -%}

#

not sure how it will handle that after 10 minutes, will it will take the data from the last event that happened after the delay is over? or will it still maintain the data from the event that initiallly triggered the automation?

deft timber
#

no it will behave correctly, the data will be kept as they were at the moment of the trigger

lapis quarry
#

cool 👍

deft timber
#

I have the same feeling :-). What you want to do is just checking the state of the trigger.data.entity_id right ? So you can just verify {{is_state(trigger.data.entity_id, 'on') ? Or am I missing something

lapis quarry
#

not really, I want to iterate trough a bunch of sensors, all the ones in that particular room, and if any is open let the condition pass

deft timber
#

ok, I understand. I propose this, but it is not a big improvement
{%- set room_number = trigger.event.data.new_state.object_id[-3:-1] %} {% set ns = namespace(result = False ) -%} {%- for x in states.binary_sensor if ( 'windowbr' in x.object_id and room_number in x.object_id and 'batt' not in x.object_id and x.state != 'off' ) or ( 'doorbr' in x.object_id and room_number in x.object_id and 'batt' not in x.object_id and x.state != 'off' ) -%} {%- set ns.result = True -%} {%- endfor -%} {{ ns.result }}

lapis quarry
#

yes that is what I meant, so that will evaluate false and not pass even though it doesn't output false, right?

#

ohh yes it does because you set it at the namespace

#

i see

deft timber
#

yep

lapis quarry
#

excellent, yes makes more sense 😎

small wolf
#

need a little help with a template. I'd like to take a value from a sensor at time = 0 and take a second value from the same sensor at t=1 (or any number). Then I'd like to subtract the two and see if the number is positive or negative. Then use that value to indicate if a device is running or not.

#

I'm not sure how to get 2 subsequent values from one sensor.

radiant pewter
#

Could someone point me in the right direction? I would like to create a template for a toggle switch that calls a service. Is that possible?

deft timber
#

what do you mean by 'a service'

silent barnBOT
buoyant pine
#

@deft timber something like light.turn_on, switch.turn_on, etc.

radiant pewter
#

So the Nissan Leaf integration allows you to call a service to start charging the battery. The service needs the VIN of the car to run. Using the HomeKit integration I would like to have a toggle switch in the home app that calls the start charging service.

#

I looked at switch.template but can’t get it to work.

buoyant pine
#

what problem were you having?

#

alternatively, expose an input_boolean to homekit and use an automation that runs that service when the boolean is turned on (and turns the boolean off after)

#

@radiant pewter

lapis quarry
#

Does HA allow to use a for loop to autopopulate the list of entity_id in a service call template?

thorny snow
#

Hello.

inner mesa
#

@lapis quarry Yes, I’ve done that by building a comma-separated list

lapis quarry
#

I have:```
- service: switch.turn_off
data_template:
entity_id: >
switch.airconbr{{ room_number }}a
- service: switch.turn_off
data_template:
entity_id: >
switch.airconbr{{ room_number }}b

#

@lapis quarry Yes, I’ve done that by building a comma-separated list
@inner mesa

    if ( 'airconbr' in x.object_id and room_number in x.object_id ) -%}
{%- if loop.first %} {% elif loop.last %}, {% else %} {% endif -%}
  {{ x.entity_id }}
{%- endfor %} ```

Outputs: switch.airconbr11a, switch.airconbr11b
#

would that work as input for the entity_id list?

inner mesa
#

Try it?

lapis quarry
#

yes, just checking if that is what you meant by a coma separated list

#

because this is a string

#

I think 😅

#

let me try

deft timber
#

@thorny snow maybe with this?
entity_id: > {{'climate.kitchen,' if is_state('input_boolean.kitchen_window', 'off') }}climate.living,climate.bathrooms,climate.office,climate.bedroom

thorny snow
#

@deft timber I'll try that. Thank you!

quiet kernel
#

Hi all, I posted this also in #automations-archived but I got redirected here. @pallid anchor, If desired, pls remove one of the two posts.

I'm looking for a way to get the parent device of an entity so that I get to another sibling entity (are entities male or female ;)). I can template my way around it but it's not foolproof. I am trying to achieve this: trigger.event.data(.state).PARENT_DEVICE.sibling_entity.state. Thanks.

lapis quarry
#

is it possible to nest the choose function?

lapis quarry
#

I just wrote this automation: https://paste.ubuntu.com/p/XqmYG5vM3b/

Im trying to figure out how I could do it to have 2 different delays where the action starts based on what entity triggered the automation (window or door)

lapis quarry
#

Is it possible to add a template in the delay?

inner mesa
#

This action allows you to select a sequence of other actions from a list of sequences. Nesting is fully supported.

#

All forms accept templates.

lapis quarry
#

Trying this but doesn't seem to be working:

    action:
    - delay: >
       {%- set room_number = trigger.event.data.new_state.object_id[-3:-1] %}
       {%- set room_type = trigger.event.data.new_state.object_id %}
       {%- if room_type.object_id.startswith('windowbr')-%}
         {{ states('input_datetime.windowbr[room_number]_timeout') }}
       {%- elif room_type.object_id.startswith('doorbr')-%}
         {{ states('input_datetime.doorbr[room_number]_timeout') }}
       {% endif%}```
 🤔
inner mesa
#

what does that spit out in devtools -> Templates?

#

it looks like it may be a datetime object, which isn't one of the options for delay:

lapis quarry
#

UndefinedError: 'str object' has no attribute 'object_id'

inner mesa
#

there ya go

lapis quarry
#

what does that mean? struggling to undestand

inner mesa
#

you'd need to give those variables values in devtools -> Templates, of course

lapis quarry
#

yes I think I am

inner mesa
#

what did you actually paste in Templates?

lapis quarry
#

This is what im trying in the template editor:

{% set room_type = states.binary_sensor.windowbr08a.entity_id %}
       {%- if room_type.object_id.startswith('windowbr')-%}
         {{ states('input_datetime.windowbr[room_number]_timeout') }}
       {%- elif room_type.object_id.startswith('doorbr')-%}
         {{ states('input_datetime.doorbr[room_number]_timeout') }}
       {% endif %}```
#

sorry I edited it because I pasted wrong, now its the right version I expect to work

inner mesa
#

looks like room_type needs to be object_id?

#

binary_sensor.xxx, where object_id is xxx

#

just based on your initial template

lapis quarry
#

entity_id contains also the object_id so it should work when in the if i compare the object id, right?

inner mesa
#

if you're going to test, do the same thing you're doing for real

lapis quarry
#

your right, yes, anyway I tried both

#

that is why I changed it

#

get the same error

inner mesa
#

that whole thing just doesn't make sense

#

you already have the object_id and you're trying to get another object_id out of it

#

you only need to do it once

lapis quarry
#

LOL welcome to my world 😂

inner mesa
#
{% set room_number = states.binary_sensor.windowbr08a.object_id[-3:-1] %}
{% set room_type = states.binary_sensor.windowbr08a.object_id %}
       {%- if room_type.startswith('windowbr')-%}
         {{ states('input_datetime.windowbr[room_number]_timeout') }}
       {%- elif room_type.startswith('doorbr')-%}
         {{ states('input_datetime.doorbr[room_number]_timeout') }}
       {% endif %}
#

that's why you were getting that error

#

see the diff?

#

in both templates, room_type is already the object_id of the entity, which is a string. you just need to test the string

lapis quarry
#

I see

#

still I get Unknown error

inner mesa
#

I don't have your whole setup and can't test it

#

without generating your environment

#

test each piece and go from there

lapis quarry
#

but i´m just checking and that is how I have it written inside the rest of the automation and it works in other places.. 🤔

inner mesa
#

same advice

torn meteor
#

ok have an issue with a light template... i need to convert string "00FFAA" to (h, s)

#

or the other way around. either direction works

lapis quarry
#

ok thanks I will keep testing lets see 😊

inner mesa
#

it would take forever for me to mock something up and make it work, and then I'm sure it wouldn't work for you

#

and then we'd be working on that. And I have a day job 🙂

lapis quarry
#

Absolutelly no prob, I apreciate the help

#

I just found it woirks when I remove the [room_number]

#
         {{ states('input_datetime.windowbr[room_number]_timeout') }}
       {%- elif sensor_type.startswith('doorbr')-%}
         {{ states('input_datetime.doorbr[room_number]_timeout') }}
       {% endif %}

       {%- if sensor_type.startswith('windowbr') -%}
         {{ states('input_datetime.windowbr08_timeout') }}
       {%- elif sensor_type.startswith('doorbr')-%}
         {{ states('input_datetime.doorbr08_timeout') }}
       {% endif %}```
#

second works one

inner mesa
#

I don't think that's the syntax that I gave you before

lapis quarry
#

if i print {{room_number}} it prints 08

inner mesa
#

didn'

#

didn't I help you with that before?

#

or was that someone else?

lapis quarry
#

yes just now

inner mesa
#

like yesterday or the day before

lapis quarry
#

its the same sintax 🤔

#

yes its possible

#

ahhh toiur right

#

hang on, my bad

#

gotcha

inner mesa
#

you made up something else

#

you'll need to modify it, but that format should work

lapis quarry
#

yes i just remembered, my bad, been at this whole week my head is a bit fried allready

#

still doesnt seem to work 🙄


{{ states('input_datetime.['windowbr' + room_number + '_timeout']') }}```
lapis quarry
#

Cant seem to figure it out, it works to extract the timestamp: {{ (states.input_datetime['windowbr' + room_number + '_timeout'].attributes.timestamp ) }}

inner mesa
#

What is your goal?

lapis quarry
#

I just want to use this in the template in the delay

#

im thinking I will use the timestamp attribute as it outputs seconds from what I see and that should work ok for the delay, but still I would like to understand what im doing wrong for it to not work in the first example

inner mesa
#

Review the docs that I posted earlier for what forms a delay takes

#

Does your template produce one of them?

lapis quarry
#

yes it does that is what im saying

inner mesa
#

The time stamp is seconds from 1970

#

What delay do you actually want?

lapis quarry
#

the timestamp atrribute outputs 300 (seconds) instead of 00:05:00 which is what I was trying to output

#

the delay will accep both

inner mesa
#

That’s returning a datetime

#

Ok

lapis quarry
#

{'editable': False, 'has_date': False, 'has_time': True, 'hour': 0, 'minute': 5, 'second': 0, 'timestamp': 300, 'friendly_name': 'Windows Auto OFF Timeout Room 08'}

#

these are the atributes

inner mesa
#

You’re trying to figure out why the timestamp works and the state doesn’t?

#

Cant seem to figure it out, it works to extract the timestamp: {{ (states.input_datetime['windowbr' + room_number + '_timeout'].attributes.timestamp ) }}

#

Does that output 300?

lapis quarry
#
{{ states('input_datetime.windowbr08_timeout') }} This works, outputs 00:05:00

{{ states('input_datetime.['windowbr' + room_number + '_timeout']') }} this doesnt work

{{ (states.input_datetime['windowbr' + room_number + '_timeout'].attributes.timestamp ) }} This works and outputs 300
inner mesa
#

Well, what is the state of that entity?

#

Oh, I see

#

I see what you’re talking about now

#

You’re making up your own syntax again and reusing the same quotes

lapis quarry
#

I´ve tried all combinations I can think of

#

😅

inner mesa
#

Just replace . attributes.timestamp with .state in the last one

#

Stop trying to put [] inside a quoted string

lapis quarry
#

yes that did it

inner mesa
#

And then don’t try to put more single quotes in the same quoted string

#

Hopefully you can see how that will confuse the parser

#

Anyway, it’s working now?

lapis quarry
#

I dont really get what the quotes do and the diference betwen single and double quote

#

yes its working now

inner mesa
#

Single and double quotes both denote a string

#

If you use one kind of quote to surround something you need to use the other kind of quote inside

#

Otherwise, you’ll confuse the parser because it thinks your ending the whole quoted string, but you’re really just trying to quote a substring in there

lapis quarry
#

ahh I see, that makes sense, because it reads the line linearly I asume?

inner mesa
#

Yes

#

‘ “ “ ‘ or “ ‘ ‘ “

lapis quarry
#

yes I understand what you are saying

#

actually the template editor would stop erroing out when I did that

#

but I wasnt getting the value, was getting unknown as result

#

awesome point noted 😄

#

one question, does the template editor write to the log file?

#

because I have a bunch of errors in it I suspect might be coming from the template editor?

torn meteor
#

is | format a valid filter?

silent barnBOT
dreamy sinew
#

The basic filters can be found there

torn meteor
#

thanks.

dreamy sinew
torn meteor
#

ok. next question and the heart of the matter. i'm attempting to convert r, g, and b values to hex in the template language. This is what i have - not tested yet. Any glaring problems?

#
    {%- set rx = ""|join("%02X" % (255*r)|round(0)) %}
    {%- set gx = ""|join("%02X" % (255*g)|round(0)) %}
    {%- set bx = ""|join("%02X" % (255*b)|round(0)) %}
    
    {{ rx }}{{ gx }}{{ bx }}
inner mesa
#

@lapis quarry Yes, it interprets in real-time and spams the log

torn meteor
#

gah. not giving me any output 😦 -- anyone familiar with what i'm trying to do here?

#
{%- set r = 120 %}
{%- set g = 10 %}
{%- set b = 200 %}
{%- set rx = ""|join("%02X" % r) %}
{%- set gx = ""|join("%02X" % g) %}
{%- set bx = ""|join("%02X" % b) %}

HEX: #{{ rx }}{{ gx }}{{ bx }}
#

bad copy pasting from interwebs. this is now working!

#
{%- set r = 120 %}
{%- set g = 10 %}
{%- set b = 200 %}
{%- set rx = "%02X" % r %}
{%- set gx = "%02X" % g %}
{%- set bx = "%02X" % b %}

HEX: #{{ rx }}{{ gx }}{{ bx }}
inner mesa
#

I don't know what joining something to an empty string ("") was supposed to do?

torn meteor
#

yeah i took this from a different context, which was bad and i'm a bad person: rgbhex = ["".join("%02X" % round(i*255) for i in rgb) for rgb in rgbs]

#

where rgbs is an array of (r,g,b) vals

inner mesa
#

magic

torn meteor
#

it really is. i have no flipping clue how doing "%02X" % 255 gives you FF

inner mesa
#

that part of it makes sense to me - you're just providing a format string and a variable

#

or a value

dreamy sinew
#

Old school python string formatting exposed out through jinja

#

The full thing you listed is list comprehension with 2 inline loops

inner mesa
#

oh, I see it now

#

I get the join(....) part now, but what is "".join(...) doing? start with an empty string?

#

I guess it's just a method of a string and doesn't exist on its own

torn meteor
#

maybe it forces it to be cast as a string instead of whatever else?

inner mesa
#

that's what I thought originally, but I think it's a string method rather than a standalone function that generates a string

#

I'm sure that phnx is coming up with some crazy template optimization right now that we'll see in a few hours

#

I, for one, look forward to it

torn meteor
#

well my whole thing to go from (h, s) to HEXHEX is here. not quite working though.

silent barnBOT
torn meteor
#

setting it as the value for input_text is choking with a unsupported operand type(s) for -: 'str' and 'int' error

inner mesa
#

that's quite insane

torn meteor
#

thank you 🙃

inner mesa
#

you're trying to turn hue, saturation into redgreenblue?

#

I don't know what that's doing

torn meteor
#

h,s >> r,g,b >> hex (FF00E7)

dreamy sinew
#

<separator>: str

#

The string class has a function join() that accepts an iterable

#

", ".join([1, 2]) -> "1, 2"

torn meteor
#

setting it as the value for input_text is choking with a unsupported operand type(s) for -: 'str' and 'int' error
@torn meteor any idea what this is about @dreamy sinew ?

dreamy sinew
#
'1hi RobC2hi RobC3hi RobC4'
inner mesa
#

got it

dreamy sinew
#

Yeah needs to be a string

#

List objects need to be strings

torn meteor
#

it's failing at all of these lines:

#
{%- set f = h * 6 - i %}
{%- set p = v * (1 - s) %}
{%- set q = v * (1 - f * s) %}
{%- set t = v * (1 - (1 - f) * s) %}
dreamy sinew
#

H, I, and v aren't set anywhere

#

Or s

torn meteor
#

ok. in my full code they are, sorry. but i see the issue now is the original inputs from the other input_number helpers are the root cause

torn meteor
#

a tiny bit of help understanding this debug statement:

#

Luxafor Set Color: Error executing script. Invalid data for call_service at pos 1: value should be a string for dictionary value @ data['value']

#

in that script, pos 1 would be... the first item in the sequence?

inner mesa
#

Need to see the whole thing. A script?

torn meteor
#
luxafor_color:
  alias: Luxafor Set Color
  sequence:
  - service: input_text.set_value
    data:
      value:
        '[object Object]':
    entity_id: input_text.luxafor_color
  - service: rest_command.luxafor_color
    data:
      color: '{{ states("input_text.luxafor_color") }}'
  mode: single
  icon: mdi:flag
#

oh my god. how did that object object get there??

dreamy sinew
#

lol

inner mesa
#

🤷‍♂️

torn meteor
#

ugh. i think going back and forth between the UI and YAML is causing issues

inner mesa
#

Suggest to stick with YAML

dreamy sinew
#

use the YAML luke

torn meteor
#

ok, haha. i am torn. when i have that big chunk of logic that converts things to hex, what/where is the best way to feed that value to the input_text.set_value thing?

inner mesa
#

Figure it out, get comfortable with it, profit

torn meteor
#

right now it's set as the argument i am passing to another script

#

and when i checked yaml, it got all reformatted with new lines and escape slash bullshit

dreamy sinew
#

the ui is...special

inner mesa
#

That thing is not intended for the UI

dreamy sinew
#

its concept of double quotes is terrible XD

#

''thing''

#

🤢

inner mesa
#

I didn’t know that you could just stack single quotes before

dreamy sinew
#

yeah, apparently valid

torn meteor
#

ikr

dreamy sinew
#

though in python """Thing""" is a thing

inner mesa
#

‘’’’ foo ‘’’’

#

A different thing

torn meteor
#

that used to be a nicely formatted series of lines

dreamy sinew
#

UI also alpha-sorts everything which is obnoxious

torn meteor
#

the plan was, this convert script does the math, then sends the output to the set color script

inner mesa
#

I tried to turn it into a python_script and got bored trying to make it work

torn meteor
#

my conversion thingy?

inner mesa
#

Yes

torn meteor
#

😬

#

well i fixed some problems in it.

inner mesa
#

It offends my sensibilities in its current form 🙂

torn meteor
#

i'm sure it does haha. i planned on slimming it down (using maps/objects for one) once i got the prototype working

#

but i need help figuring out how to get that final HEX value over to input_text.luxafor_color

#

i'm not sure if the script spaghetti isn't executing due to YAML issues, or it is and the thing sent to the next script is in a bad format

inner mesa
#

Just do what you’re already doing

torn meteor
#

so the last line of all the math code is {{ thehexvalue }}. Is that compatible as a argument to the next script? it doesn't seem to be reading as a string

inner mesa
#

All templates produce a string for now

torn meteor
#

got it. that's why i see a lot of |int'ing around the web

dreamy sinew
#

yup, just about everything comes through as a string

torn meteor
#

when sending a script argument, can i set an argument's value to >- long list of script commands and then output? i read somewhere that only data_template supports that

dreamy sinew
#

unless value_json for the things that produce it

#

old news

#

if you want a multi-line template, use : >-

#

also useful to strip whitespace on your logic lines

#

{%- -%}

torn meteor
#

right. did that. and that can be used with both {{ }} and {%- ... %} directives on any key value?

dreamy sinew
#

if you just have a single line output statement, its easier to just : "{{}}"

inner mesa
#

data_template is no longer needed. Just use data:

torn meteor
#

just trying to rule out syntactical errors

#

ok

dreamy sinew
#

i refuse to look at pictures of text

inner mesa
#

Especially that block of crap

torn meteor
#

so sorry. let me clean it back up and paste bin it.

inner mesa
#

looks okay to me

dreamy sinew
#

man, my kingdom for var names

inner mesa
#

still a monstrosity, but hopefully a functional one

torn meteor
#

phnx i have no idea why they are named that either. stack overflow code.

#

should entity_id and be a child of data? i see it both ways in different places

#

like, when calling a script service

inner mesa
#

it can usually go either way

#

if you're providing a template for entity_id, it needs to go under data. otherwise, it can go outside

torn meteor
#

ok. i always felt like it looked neater under data, but whenever i save things HA moves it up a level 🤷‍♂️

#

yaml and i have never been close friends...

dreamy sinew
#

that's one of those "it depends"

#

you can push it inside if you are setting via template

torn meteor
#

its ALIVE

#

thanks for all your feedback

#

cookies for everyone 🍪 🍪

#

this is what i do with my night off from the kids.

dreamy sinew
#

hahaha

torn meteor
#

big picture: when i take a work phone call on Teams on my laptop, the HA MacOS will trigger the mic ON sensor, which will change these Luxafor lights to RED. so that my wife and kids won't bother me at home.

#

this has been a pipe dream for years until i finally switched to Home assistant

#

❤️

dreamy sinew
#

lol nice

#

daughter is 2 so no amount of signaling will affect what she does

torn meteor
#

true. we've got a nanny to round up the twins though

dreamy sinew
#

when everyone was home that was...fun

#

baby is back in daycare and wife is back teaching so its all quiet during the day again

torn meteor
dreamy sinew
#

lol

ruby vault
#

@violet oyster I tried your idea without success. I'll play with it more later.

torn meteor
#

abs() is undefined

#

can i not do absolute value?

#

bah. there's a filter version with a pipe nvmnd

dreamy sinew
#

Difference between a filter and a global there

torn meteor
#

the one i was using "snapped" colors at 60° increments. so you could only get tints of red, green, blue, cyan, magenta, and yellow

#

the new one is nearly completley accurate

#

it also explains what some of those weird variable names were

desert quail
#

How I can remove completly the header of HA. I have a cellphone that I will use like a switch wall

#

but the header of HA occupies 10% of the screens

deft timber
desert quail
#

its dead

inner mesa
desert quail
#

@inner mesa thanks

#

@inner mesa a quick question, if I install this theme, and then put some stuff in yaml, it only runs if the user selects that theme, right?

inner mesa
#

Correct

nocturne chasm
#

Is there a better way to do multiple is_state with same entity_id and different states other than connecting them with an or?

rugged laurel
#

{{ states('entity_id') in ['your', 'list'. 'of', 'states'] }}

nocturne chasm
#

Thank you

raw wharf
#

Hi guys.

#

I need some help.
I want to make an automation with the following criteria:
IF switch "xyz" is not ON by 8:15am than turn ON.
This will happend from Mon-Fri, except on days marked as holiday on google calendar.
Any ideas?

#

tks

brisk temple
desert quail
#

@inner mesa where I change the css? in configuration.yaml ?

#

because i dont have any instroctions where to change it 😮

inner mesa
#

they're themes

#

if you're unfamiliar with adding themes, then you're better off using one of the "Soft UI themes" that I mentioned earlier

#

installed from HACS

desert quail
#

just ading these in themes?

inner mesa
#

or...just install them via HACS

#

really, just do that

desert quail
#

and then I can remove the header?

inner mesa
#

install the theme and see what it does. it's just a theme, so you'd need to edit it manually to change what it does

#

for me, it shrunk the header down to a single line, but the rest of the theme was not to my liking. I'll probably try to build something manually from Thomas's directions

desert quail
#

ok

#

there is anyway to hide menu bar?

#

@inner mesa

inner mesa
#

Please don’t tag me for random questions

desert quail
#

sorry

topaz silo
#

can anyone help me figure out why this does not round... {{ (states('sensor.goodwe_e_day') | float) + (states('sensor.goodwe_e_day_2') | float) | round(2) }}

#

hmm, i think i know.. lol

#

{{ ((states('sensor.goodwe_e_day') | float) + (states('sensor.goodwe_e_day_2') | float)) | round(2) }} would this work?

buoyant pine
#

or just

{{ (states('sensor.goodwe_e_day') | float + states('sensor.goodwe_e_day_2') | float) | round(2) }}
topaz silo
#

ok, thanks. still very new to all this stuff

spiral imp
#

I have this template that works fine:
The high today is {{ states('sensor.dark_sky_daytime_high_temperature_0d') | round(0) }}ºF with a low of {{ states('sensor.dark_sky_overnight_low_temperature_0d') | round(0) }}ºF and {{ states('sensor.dark_sky_precip_probability_0d') | round(0) }}% chance of {{ states('sensor.dark_sky_precip_0d') }}.

But I need to account for an "unknown" value for sensor.dark_sky_precip_0d and have it return "precipitation". I know it needs to be something like {{ if is_state('sensor.dark_sky_precip_0d', 'unknown') precipitation }} but how do I get the 'else' in there if the state is not "unknown"

dreamy sinew
#

{{ ' chance of {}'.format(states('sensor.your_sensor')) if not is_state('sensor.your_sensor', 'unknown') }}

#

Oh, got that backwards

inner mesa
#

meatballs

dreamy sinew
#

{{ states('sensor.your_sensor')) if not is_state('sensor.your_sensor', 'unknown') else 'parcipitation' }}

spiral imp
#

thanks

torn meteor
#

hey there - template light. possible to include an effect list on it? i don't see it in the docs, but normal lights support this..

torn meteor
#

related question. how does one calculate the bit number for supported features?

#

it seems i might be able to trigger the effect list by adding in the right number for that (+4)

dreamy sinew
#

looks like it doesn't support it

torn meteor
#

😦

torn meteor
#

i know this has been asked on the web before, but is there any way to put a template light into a room/area

#

4/5 of my lights are in there (real lights)

#

but since the template light is just an entity (no device), i can't put in in an area

fossil venture
#

No there is no way to do that yet.

thorny snow
#

Hi , can somebody help me with a template? I've got a working binary sensor based on two time helpers and it works great. It only needs to be evaluated every minute. I followed the instructions on the https://www.home-assistant.io/integrations/time_date/ but I must be missing something.

#

working sensor that does no trigger every minute

#

created time sensor

#

modified binary sensor

#

any help is really appreciated

brisk temple
#

{% set n = states('sensor.date_time_iso') %}

#

@thorny snow your line after that doesn't seem to work either

#

ah, because you moved it from now()

#
{% set n = as_timestamp(states('sensor.date_time_iso')) %}
{% set hour = n | timestamp_custom('%H') | int %}
{% set min = n | timestamp_custom('%M') | int %}
{% set n = (hour*60+min)*60 %}
torn meteor
#

No there is no way to do that yet.
@fossil venture are there plans to?

fossil venture
#

I believe so.

ionic hazel
inner mesa
#

if you can do that, and I'm not sure you can, then you'd need to make a list by adding " - " to the beginning of each block

ionic hazel
#

is "block" each service i am trying to do?

inner mesa
#

yes, just like you'd do for a script/action

ionic hazel
#

Okay I think script is the way to go, Tinkerer also suggeested going that route