#templates-archived
1 messages · Page 105 of 1
oh didn't know that
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
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
thanks petro, worked for my case
makes sense
@lapis quarry in your case you could just alter that automation to fit your automation
that's a 2 for 1, you can take the rest of the day off
@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 }}
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 ':'
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+
are there errors in the logs?
no, its loading fine
why do you have initial_state off
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
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
yes I can see the event fire
although a few other events fire in succession after the timer event (timer save etc)
it should still turn on your input_boolean
when it fires are there errors in the logs?
correct, but its not changing
is the input boolean on?
yes, have tried with both states in the timer idle and active
and the boolean on and off
does not work either way
whats the name of the input boolean?
input_boolean.block_keyring0xx
should be working based on all that information, otherwise there should be errors in your logs
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
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') }}
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
@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.
I was wondering about that, will test and see how it goes
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 %}
use 2 set statements
or you need to tuple your states calls
{{ foo }}
{{ bar }}```
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 %}
Ahh, ok i found the problem i missed the second float statement
@mighty ledge Im trying to implement your method in some other places, can you check if this makes sense? https://paste.ubuntu.com/p/ZWXCCqstTj/
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 .
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
I recommend reading through this, especially the latter posts regarding optimizations: https://community.home-assistant.io/t/heads-up-upcoming-breaking-change-in-the-template-integration/223715
As I mentioned in the other channel, it won't listen for changes to entities that won't affect the result of the template
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 🙂
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
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?
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
it's just a calculation I'd like to have accurately set between some hours
is it not working?
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
I would recommend reporting an issue if you can identify one, but not preemptively
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
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.
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
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
exactly, it isnt providing any extra security. If someone can read the shell command file/configuration.yaml then they can read secrets.yaml
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.
@umbral bridge posted a code wall, it is moved here --> https://paste.ubuntu.com/p/cTs3PP886g/
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.
@umbral bridge posted a code wall, it is moved here --> https://paste.ubuntu.com/p/kwdz5Sq3QY/
@umbral bridge
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
The automation code is https://paste.ubuntu.com/p/cTs3PP886g/ and the Event data is https://paste.ubuntu.com/p/kwdz5Sq3QY/ . I'm assuming it could be a templating issue, but the various iterations I've tried didn't work.
Apologies it just started working suddenly.
Nvm no it didn't. Was confused of a similiar automation that triggered.
That template will always be false
oh really? i was testing it with != since i do have an id
ill delete the answer i guess ha
You did a compare with strings on both sides (both sides was quoted), because of that a would never match b
== None
yep that sure works
@umbral bridge
{{ trigger.event.data.new_state.context.user_id == None }}
Thank you @rugged laurel and @violet oyster ! It worked!
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.
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
I see, thanks barbados, but I think my use case that would not work
Create a script where you use a variable to do stuff.
Call that script an pass in the variable form the automation action
@rugged laurel always has better ideas than me
dont think it would work either for what im trying to write..
It will
what are you trying to do??
this, and now I need to add a bunch of other sequences which will also use the same variables
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?
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
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 %}
🤔
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.
Errors?
@hollow stag posted a code wall, it is moved here --> https://paste.ubuntu.com/p/p8YBgSh3sY/
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.
Try
> Server Controls > Reload template entities
ok, then it works. Is there a way to delay that template loading on reboot?
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
Want to see what issues are open (or were open and are now closed)?
- The core (backend) - for HA itself, and integrations
- The frontend (UI) - for cards and display issues
- The Supervisor
- HassOS
- The documentation
Finally, don't forget to check for any alerts
Are these sensors from MQTT?
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
yeah ok, maybe i'm worng. i'm using the default built-in version, haven't moved to the z-wave2mqtt yet
Ok, then not MQTT
They’re both OZW, just different versions and use different mechanisms
Same advice
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
for what exactly? using variables in scripts?
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
its actually not in a script, its inside in a automation I´m writing
an automation can call a script
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..
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
let me try
awesome Rob, that seems work in the template editor {{ as_timestamp(states.group['room' + room_number].last_changed) }}
had to dig up the syntax from the forum, but it makes sense
what do the [] do?
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
amazing, just tested the automation and it also works 😄
Thanks Rob, appreciate it, spent a few hr trying random stuff 😅
np, glad it's working
is my indentation on this wrong? https://hastebin.com/ravurikihi.less
looks okay to me, other than data_template: should be data:
oh sweet
does it not work?
i gotta ton of red lines in VS Code, so i didnt actually check config yet. This is my first template
im just copy/paste this post right here, https://community.home-assistant.io/t/how-to-control-input-source-on-denon-avr-with-alexa/153661/2
and swapped out his denon with mine
and the red lines in VS Code are related to that?
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
2 spaces or no spaces is okay as long as you're consistent. 1 space is not
ohhhh.
sweet
Okay okay in my yaml it's 2 spaces everytime
Other than that just chagne data_template to data ?
you should do that, yes
if I paste that right into my configuration.yaml, VSCode is fine with it
Did you have 2 spaces or 0?
I pasted what you posted
Gotcha. I got no red lines now, lets see how it goes
Okay so now that that's outta the way, instead of "HDMI 1" as the source it should be "HEOS Music" . Is it as simpel as swapping the two? https://hastebin.com/alazakonep.less
you didn't change data_template: to data:, but I expect so
ahh dangit
try it?
Trying now
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?
it's not a standard thing
well, poop
It worked! Thanks, Rob!!!
@tight parrot Looks like you're looking for this: https://www.home-assistant.io/integrations/version/
This is what I was initially following, I'm not sure where that current_version entity came from: https://community.home-assistant.io/t/update-notifications-core-hacs-supervisor-and-addons/182295/16
probably from the integration that I pointed to
perhaps, it's not mentioned in that thread from what I can find, though
or as an attribute for sensor.supervisor_updates
regardless, there's a command_line sensor someone added which gets the current version from the local API, https://community.home-assistant.io/t/update-notifications-core-hacs-supervisor-and-addons/182295/80?u=aph3rson
so you have what you need?
yeah, I'm good, thanks
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 ?
@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 There are others who can probably give you better options but you can always update the entity through automation with homeassistant.update_entity service
i try this one to: '{{ states("sensor.date_time") and (now().astimezone().tzinfo)| string == "IDT" }}'
that will work too
but also didn't work
try states('sensor.date_time_iso')
not working
well like i said you can always update it through an automation
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
hi! is there a way to change icons in the lovelace template for climate? function for cooling shows heating
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
A input_number goes from 70 to 100. How do I create a template light from it that works in HomeKit?
it could work with something that calculates it but i don't know how 😉
@gusty nimbus you may want to look into History Stats
@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
@little gale i can click on the stats yes and calculate in my own head yes 🙂
that sensor outputs an integer right?
It can do more: https://www.home-assistant.io/integrations/history_stats/#type
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? 🙂
@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
i want to make an other sensor for per day
how and what could i set ? 🙂
im not very good in this things :p
@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
This could be of more help: https://www.home-assistant.io/integrations/statistics/
hm ok
Has all those
yeah statistics integration could definitely make it easier
and change max_age to 24 hours ?
hm ok i start to understand i think
You could make a template sensor to extract total
sensor:
- platform: statistics
entity_id: sensor.gas_verbruik
- platform: statistics
entity_id: sensor.gasusageperday
max_age:
hours: 24
something like this?
its a binary sensor?
no he just copied the example i think
oh
yes i copyed and changed 🙂
the entity_id would be the id of your rest sensor
then set name: to name your new stats sensor
rest sensor means the one i allread had that keeps on counting up ? 🙂
oh ok
i edited
you only need one, with max age 24
and do i have to get it resetted at 12PM ?
the statistics sensor will show a rolling average of the last 24 hours at any point in time
oh ok
so if i set this up at 13:42 like its here now it will count till tommorow same hour
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
or i find a way to manual reset it this night at 00;00 my self? :p
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?
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
@violet oyster
so i think the best way the input numbers?
if you want it to be per day, then yes. in my opinion at least.
are you using yaml?
yep
give me a minute
sure you could have more to don't rush many thanks on advance
alright this isnt gonna work but i have another idea. stand by
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?
now() is a function. It won't trigger automations.
Create and use sensor.time instead.
@gusty nimbus try this https://paste.ubuntu.com/p/qSZ89qgbF5/
ok tx sec
should work immediately but let me know if it doesn't
input_number:
where to put that in configuration.yaml ?
the automation part in automations.yaml i think
either make it a package or copy each part to the correct area
oh i get it
(packages make stuff like this much easier)
yes i know i still have to do that 😉
maybe a question
gas_at_1159:
here the timezone is like in the 24 numbers
oh yeah my bad
so gas_at_2359 ?
it works the same here too i just had a brain fart lol
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 😉
no, as long as packages: is configured in configuration.yaml
keys in packages don't conflict with keys in configuration.yaml
oh ok
i will try that 😉
then if it works its later on a good time to put it all on seporated things :p
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
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
homeassistant:
packages: !include_dir_named gas
although again, if you want actual months instead of just 'past 30 days' then yeah
i would just do a folder named packages then make gas.yaml
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 😉
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
just make sure to reload the dependencies first. input numbers then sensors then automations
does it have to be 00:00:00 ?
yep lol
lol im tired
good catch though. would have been frustrating if it didnt work because of that
idd 🙂
that looks good to me
gonne restart HA because i didn't had that packages rule 🙂
you can test it by manually triggering all 3 automations in developer tools > states
just to make sure its fine 😉
yeah youll need to restart to get packages working the first time
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 😉
honestly for someone who is new to it you understand it very well. i've given up on people many times
i'm not either, i've just been using it a few years
i have an digital electrical meter & gas i have another rpi doing the readings 😉
but gas per day wasn't supported
nice
i'm just good at finding workarounds haha. i don't know how things actually work
im an Linux user for like 20Y but this kind of scripting code automations in yaml is something else then i mostly do 😉
nice 🙂
i just switched to linux full time actually. previously i only used it on my server
ubuntu 20.04
good, now manually execute the automations in order, make sure the set_gas_yesterday one is executed last
ok gonne try
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
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
it should be 0
its 0 yes
since both numbers were set right now
gas_yesterday
8 minuten geleden
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³"
8 minutes ago 😉
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
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³"
you don't need the
- platform: template
sensors:
on the second one
but it won't hurt.
reload template entities and it should work
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
gonne show you
gas_today
3 minuten geleden
0.0030000000000001137 m³
3 minutes ago 😉
what about sensor.gas_verbruik
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?
yeah i understand
but it will be alot higher 😉
its not heating atm 😉
does it update on its self the gas daily?
gas today?
the sensors should update whenever the states of the references entities change
oh ok
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
you speak english? or dutch to ? 🙂
just english, I googled 'verbruik' lol
i'm just a dumb american who only speaks one language
lol 🙂
dumb i would not say 🙂
here in Belgium most people speak Dutch, french , german , english
french i don't know alot things 😉
that's too many languages. you guys should make up a belgian language
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
i make many faults in english but most i learned on my self 🙂
yes thats true another timezone
there its 15:04 now 🙂
09:06 here
oh just out of bed? 🙂
no, just got off work
no problem. send me a direct message if you need any more help
ok you to 😉 tx see ya later
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
Basically a toggle that allows easily pausing automations
@rain cove make a group with your automations in it and toggle the group
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
i get the entity: all part but i don't know what you mean by template. just trigger the service?
I need a switch on my dashboard to be able to call the service though. Like this: https://i.imgur.com/3RFYJwM.png
just include this automation as entity
I don't know what you mean
a template switch would work
Ok. Should I move my "all lights" switch there too? I made it as a light because I thought it had to be
Sorry... its a template that represents all entities of the light domain so I can turn them all on and off together
you could
Thanks Rob
np
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
That would require creating a group however
I am getting this warning constantly for template loop detection; https://community.home-assistant.io/t/jinja-loop-scoping-average-temperature-sensor/9845/26?u=jurgenweber
any thoughts?
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?
{% 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") }}
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.
it's supposed to convert to the local lang
YMMV
easy enough to try in
-> Templates
Wait, got confused. it probably does but oct is the same it both languages😅 woops
https://support.sendwithus.com/jinja/jinja_time/
Will take a look at this to customize it a little bit more, thank you!
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.
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?
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?
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?
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
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
{{ns.time.split(",")|min}}
not outputing anything..
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
Aleks, what is n ? Use now() instead
I'm not sure, I found the code here - https://community.home-assistant.io/t/automation-during-date-range/133814/50
set ns.time to be a list and not a string
that just looks strange
and you need added logic to split it
this is not yaml 😉
lol
it's jinja 🎉
you see?! 😄
Look a little bit higher in the page: {% set n = now() %}
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] -%}
Look a little bit higher in the page:
{% set n = now() %}
@deft timber not following
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
Ohhh, so " value_template: "{{ now().month >= 10 or now().month < 4 }}""
yep
Thanks! 😄
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
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
appending to a list is a pain in the jinja env we use
...
{% set ns.time = ns.time + [new_timestamp] %}
...
{{ ns.time|min }}```
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?
Yes, that is exactly the reason
awesome - I'll have to play around with my sensor then
unit of measurement creates a suffix rather than a prefix doesn't it?
value_template: "{{ states('sensor.washingmachinecost_today').replace('£','') | float | round(2) }}"
Wait. Does the actual state of the sensor show the £
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) }}'
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) }}
real quick, unique_id string (optional) -- does this require a machine name or human name? "my_ac" or "My AC"?
nevermind.
how to I cast a string to an entity though?
something like {{ this.gives_me.an_entity_id }}.attributes.current_temperature
you mean a variable?
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
right, was just coming to mention that after testing 🙂
states('input_text.current_ac') would be better for the interior call
prevents a failure, right?
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' }}
where?
just trying to interpret "reject if the object_id is finished in batt"
otherwise, I don't know what that means
I have binary sensors named binary_sensor.windowbrXX and binary_sensor.windowbrXXbatt
I just want it to pass with the first ones
so, not new_state.object_id.endswith('batt')
gotcha 👍
and not right?
new_state.object_id.startswith('window') and not new_state.object_id.endswith('batt')
?
looks okay
you can create a variable in
-> 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
now you lost me 😅
Regex == dark magic
lol I think ill stick with this as I barely understand it as is
I tried some stuff and lost interest
you can create a variable in
-> Templates with whatever you want to test with
@inner mesa thanks for the tip, hadn´t occurred to me, that worked
anyone albe to help with a loop warning I am getting with a sensor? https://community.home-assistant.io/t/jinja-loop-scoping-average-temperature-sensor/9845/26?u=jurgenweber
Odd, it might not like that it's doing everything twice
Oh, 2 different filters nvm
@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.
this was the original issue, just for reference: https://github.com/home-assistant/core/issues/40611
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.
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
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?
just put a delay as the first action
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
with a choose statement yes
🤔 how?
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?
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
You mean:
Delay would go here?
- choose:
- conditions:```
action:
- delay: '00:10:00'
- choose:
- conditions:
like this ?
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
you mean the delay would restart counting again 10 minutes in this case?
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
it could work I guess
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?
no it will behave correctly, the data will be kept as they were at the moment of the trigger
cool 👍
any suggestions on how to shorten the for loop in this condition? https://paste.ubuntu.com/p/pdjCMJrzyf/
It works but I have the feeling I´m over complicating it with the loop.index
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
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
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 }}
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
yep
excellent, yes makes more sense 😎
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.
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?
@radiant pewter https://www.home-assistant.io/integrations/switch.template/
@deft timber something like light.turn_on, switch.turn_on, etc.
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.
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
Does HA allow to use a for loop to autopopulate the list of entity_id in a service call template?
Hello.
Is it possible to add a condition to an 'entity_id' list using a template? Basically I'm trying to achieve something like this: https://pastebin.ubuntu.com/p/KHqJnjRx2z/ , but it's not working...
@lapis quarry Yes, I’ve done that by building a comma-separated list
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?
Try it?
yes, just checking if that is what you meant by a coma separated list
because this is a string
I think 😅
let me try
@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
@deft timber I'll try that. Thank you!
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.
is it possible to nest the choose function?
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)
Is it possible to add a template in the delay?
This action allows you to select a sequence of other actions from a list of sequences. Nesting is fully supported.
All forms accept templates.
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%}```
🤔
what does that spit out in
-> Templates?
it looks like it may be a datetime object, which isn't one of the options for delay:
UndefinedError: 'str object' has no attribute 'object_id'
there ya go
what does that mean? struggling to undestand
you'd need to give those variables values in
-> Templates, of course
yes I think I am
what did you actually paste in Templates?
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
looks like room_type needs to be object_id?
binary_sensor.xxx, where object_id is xxx
just based on your initial template
entity_id contains also the object_id so it should work when in the if i compare the object id, right?
if you're going to test, do the same thing you're doing for real
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
LOL welcome to my world 😂
{% 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
I don't have your whole setup and can't test it
without generating your environment
test each piece and go from there
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.. 🤔
same advice
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
ok thanks I will keep testing lets see 😊
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 🙂
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
I don't think that's the syntax that I gave you before
if i print {{room_number}} it prints 08
yes just now
like yesterday or the day before
its the same sintax 🤔
yes its possible
ahhh toiur right
hang on, my bad
gotcha
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']') }}```
Cant seem to figure it out, it works to extract the timestamp: {{ (states.input_datetime['windowbr' + room_number + '_timeout'].attributes.timestamp ) }}
What is your goal?
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
Review the docs that I posted earlier for what forms a delay takes
Does your template produce one of them?
yes it does that is what im saying
the timestamp atrribute outputs 300 (seconds) instead of 00:05:00 which is what I was trying to output
the delay will accep both
{'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
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?
{{ 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
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
Just replace . attributes.timestamp with .state in the last one
Stop trying to put [] inside a quoted string
yes that did it
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?
I dont really get what the quotes do and the diference betwen single and double quote
yes its working now
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
ahh I see, that makes sense, because it reads the line linearly I asume?
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?
is | format a valid filter?
Jinja is used by Home Assistant's template engine, see the Jinja Template Designer Documentation
The basic filters can be found there
thanks.
The ones that ha adds are here
https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/template.py#L770
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 }}
@lapis quarry Yes, it interprets in real-time and spams the log
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 }}
I don't know what joining something to an empty string ("") was supposed to do?
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
magic
it really is. i have no flipping clue how doing "%02X" % 255 gives you FF
that part of it makes sense to me - you're just providing a format string and a variable
or a value
Old school python string formatting exposed out through jinja
The full thing you listed is list comprehension with 2 inline loops
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
maybe it forces it to be cast as a string instead of whatever else?
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
well my whole thing to go from (h, s) to HEXHEX is here. not quite working though.
@torn meteor posted a code wall, it is moved here --> https://paste.ubuntu.com/p/rkcqzQ8DzD/
setting it as the value for input_text is choking with a unsupported operand type(s) for -: 'str' and 'int' error
that's quite insane
thank you 🙃
you're trying to turn hue, saturation into redgreenblue?
I don't know what that's doing
h,s >> r,g,b >> hex (FF00E7)
<separator>: str
The string class has a function join() that accepts an iterable
", ".join([1, 2]) -> "1, 2"
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 ?
'1hi RobC2hi RobC3hi RobC4'
got it
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) %}
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
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?
Need to see the whole thing. A script?
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??
lol
🤷♂️
ugh. i think going back and forth between the UI and YAML is causing issues
Suggest to stick with YAML
use the YAML luke
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?
Figure it out, get comfortable with it, profit
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
the ui is...special
That thing is not intended for the UI
I didn’t know that you could just stack single quotes before
yeah, apparently valid
ikr
though in python """Thing""" is a thing
UI also alpha-sorts everything which is obnoxious
the plan was, this convert script does the math, then sends the output to the set color script
I tried to turn it into a python_script and got bored trying to make it work
my conversion thingy?
Yes
It offends my sensibilities in its current form 🙂
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
Just do what you’re already doing
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
All templates produce a string for now
got it. that's why i see a lot of |int'ing around the web
yup, just about everything comes through as a string
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
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
{%- -%}
right. did that. and that can be used with both {{ }} and {%- ... %} directives on any key value?
if you just have a single line output statement, its easier to just : "{{}}"
data_template is no longer needed. Just use data:
just trying to rule out syntactical errors
ok
did you see any issues with https://imgur.com/a/Pca1Xa2 ?
i refuse to look at pictures of text
Especially that block of crap
looks okay to me
man, my kingdom for var names
still a monstrosity, but hopefully a functional one
phnx i have no idea why they are named that either. stack overflow code.
sorry not SO, the HA forum: https://community.home-assistant.io/t/using-hsv-hsb-to-set-colored-lights/15472
should entity_id and be a child of data? i see it both ways in different places
like, when calling a script service
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
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...
that's one of those "it depends"
you can push it inside if you are setting via template
its ALIVE
thanks for all your feedback
cookies for everyone 🍪 🍪
this is what i do with my night off from the kids.
hahaha
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
❤️
true. we've got a nanny to round up the twins though
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
lol
@violet oyster I tried your idea without success. I'll play with it more later.
abs() is undefined
can i not do absolute value?
bah. there's a filter version with a pipe nvmnd
Difference between a filter and a global there
FWIW, i found a MUCH better algorithm for accurate HSV to RGB conversion: https://www.tlbx.app/color-converter
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
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
You can use Custom Header from HACS (more a #frontend-archived topic)
its dead
This is your option, along with a few ‘soft UI’ themes available in HACS: https://github.com/thomasloven/lovelace-card-mod/wiki/Theme-cookbook
@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?
Correct
Is there a better way to do multiple is_state with same entity_id and different states other than connecting them with an or?
{{ states('entity_id') in ['your', 'list'. 'of', 'states'] }}
Thank you
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
@inner mesa where I change the css? in configuration.yaml ?
because i dont have any instroctions where to change it 😮
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
there's a bit more about themes here, and probably elsewhere in the docs: https://www.home-assistant.io/integrations/frontend/
and then I can remove the header?
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
Please don’t tag me for random questions
sorry
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?
or just
{{ (states('sensor.goodwe_e_day') | float + states('sensor.goodwe_e_day_2') | float) | round(2) }}
ok, thanks. still very new to all this stuff
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"
{{ ' chance of {}'.format(states('sensor.your_sensor')) if not is_state('sensor.your_sensor', 'unknown') }}
Oh, got that backwards
meatballs
{{ states('sensor.your_sensor')) if not is_state('sensor.your_sensor', 'unknown') else 'parcipitation' }}
thanks
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..
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)
looks like it doesn't support it
😦
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
No there is no way to do that yet.
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
{% 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 %}
No there is no way to do that yet.
@fossil venture are there plans to?
I believe so.
Am trying to list multiple services. My first time doing it https://paste.ubuntu.com/p/ZZHSX7kZmQ/
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
is "block" each service i am trying to do?
yes, just like you'd do for a script/action
the docs point to the normal script syntax, so just follow that: https://www.home-assistant.io/docs/scripts/
Okay I think script is the way to go, Tinkerer also suggeested going that route