#templates-archived
1 messages Β· Page 102 of 1
that would be perfect. can I get some short help with that I never tried something like that.
I use {{ relative_time (states.binary_sensor.yoursensor.last_changed) }}
oh so there is an attribute
this is an mqtt motion detector inside the camera.
i have never used a timer per se so i don't know too much about them. but it should work.
yes, i tried it. Last_changed attribute not working.
Do you have recorder integration activated ?
Yes I have
As well as history?
Apparently itβs this one that should create this attribute https://www.home-assistant.io/integrations/history/
Yes I have history too
interesting.
I see what you say, and understand it too, but my attribute last changed not working.
I want to see it on my apple watch.
This is what I wrote : {{ relative_time(states.binary_sensor.motion_detection_kitchen.last_changed") }}
Ah it works!
Sorry @deft timber Your Idea was the perfect!
It was my stupidness to misstype it!
Thank you for your kindness!
ππΌ
Barbados also thank you for the hints π
you got it
Sorry @deft timber a last question. How often does this update? I show this values on my apple watch.
Ah now its changed, but I dont know how much time spent.
According to this page https://www.home-assistant.io/integrations/template/, if you add in your sensor definition entity_id: sensor.time, it will be refreshed every minute
But hmmm, just made a little test, not sure it does...
that would be very good to know, for example for me on my apple watch would be good to always see the actual stuff not 15 minute old.
what you can do is what is proposed at the end of the webpage I linked : add an automation every x minutes that will update your template sensor using the service homeassistant.update_entity
yeah i have like 30 entities in my homeassistant.update_entity automation
understood. I can do that. Thanks for the hint guys, sounds logical and easy.
@inner mesa got it working like this https://paste.ubuntu.com/p/3wdQTWktvG/ . funny how obvious shit can be in retrospect. thanks again
@deft timber interesting,because I created a markdown card where I show this template stuff and this is showing always the actual, every second. but on my apple watch only every 5 minutes lets say.
Yes I guess that if the template is used directly in the front somewhere, it is the frontend that decides when the refresh occurs, and maybe this refresh rate is not the same on the apple watch and on the webapp ?! Just try guessing here π
yeah I think the same anyhow I try your idea with the automation.
i would guess it is the apple watch refresh rate that is the problem
if it refreshed every second it would die in an hour
not working π¦
yeah refresh every 5 minute would be also good.
but now it looks like its never doing it.
still showing the values of 20 minutes before.
but the value in the HA front end is correct?
yes, it is changing every second.
yeah. i don't have an apple watch but that has to be a limitation of the watch
you might be able to use browser_mod to force a lovelace refresh on the watch. if it is using lovelace. or is it an app?
no, android
I have app settings in IOS Home Assistant, there is an Apple Watch menu, you can change the status symbols in the front of the apple watch, where is your heart rate and things like that, it can show sensor values instead of these stuffs.
and you can write in templates. and I wrote in this: {{ relative_time (states.binary_sensor.motion_detection_kitchen.last_changed)
}}
and its showing 16 minutes. he thinks this is the time left since I was in the kitchen.
but I went in 10 minutes ago, and on my lovelace its changed.
it showing 9 min 30 sec.
but my watch still shows 26 minute old data.
I don't have an apple watch sorry... does it do the same for all sensor ? It displays an old value ? Or only with this template ? If only with this template maybe you can create the template sensor we talked about, refresh it every minute with an automation, and display the value of this sensor instead of displaying the template ? Just an idea, I can't test it
oh !
what happens if you turn off bluetooth on your iphone to disconnect the watch and then turn it back on to reconnect? does it update?
I tried it, didnt worked.
still showing 32 minute old data.
I really dont understand why is it a feature if it cannot be refreshed ever.
I can do a preview test.
on my phone with the template.
Yes
its working on my preview.
ah now its refreshed on my watch!
i'm wondering if you have the feature 'automatically close connection' turned on for the iphone app
i'm almost certain that is the problem
could be wrong but i have a strong feeling
or possibly if the iphone has some kind of power saving feature that puts the app to sleep
it won't update on the watch if it doesn't update on the phone.
nothing like this on iphone
as I know.
everything set correctly on my phone
I check again.
so in your HA iphone app, click on your username at the bottom of the left pane
and see if 'automatically close connection' is turned on
need restart for that on the server?
no
that feature was introduced pretty recently and caused a lot of problems for me
it is intended to save bandwidth and battery but will also ruin functionality for things like you are trying to do
is the app open on the phone?
i wonder if there is a similar setting for the watch itself. i have no idea what the watch app is like
I found something.
on the companion ios app docs.
By default the app will sync your sensor every 30 minute although the first update after creating a sensor may take longer.
can it be adjusted?
No, only if you enable Background Fetch, what I think its enabled and set it on your apple watch home screen
both was done already.
15 minute left since the last watch update.
I'll wait again 15 minute and lets see if its real.
If yes its still bad π
motion detection with 30 minute delay a bit useless I think so.
i agree
I dont know what should I use then, instead of that sensor.
an android, lol
way more options with android
The best would be an Apple HomePod
but too expensive
you can create automations on IOS with a default software called Shortcuts.
for example Call-service from Home Assistant.
and if you name it in any language, Siri will recognize it.
Im from Hungary and none of the voice assistants speak this language
but IOS recognize it because of this shortcut stuffs.
so I would be able to do everything with voice in my own language.
Now I use google mini.
home assistant users who use apple devices blow my mind. apple's sandbox is antithetical to the whole idea of open source home automation. but to each their own I suppose.
they're just rebels
u are totally right, but still apple have more intelligent things like android.
and nobody can no.
because what I told it cannot be done anyhow with any apk or hack or anything on android.
so little differences, but yes on the other side on android you can do 99% more things.
customized also
google doesn't know your language? why does it have to be siri
yes none of them know.
only Siri
also cannot speak it
but understands it.
for google will be in a 10 year period.
what language is it
Alexa will never know they announced.
that's some halfassed job done by apple
Hungarian
google home can't speak hungarian??
man that sucks
yes π
Now what im doing
I speak in english to GOogle Mini
and I wrote automations with Google Translate, so If I tell "Google turn on the livingroom light" its turn on and run Google_translate on Hungarian language and says back "Light is on" but on hungarian language with robot translate sound π
but apple homepod is about 400 usd, Google Mini I bought for 35 usd.
thats the difference, and thats the same thing nearly.
why is it important to have responses in native language?
not important
the commands would be important
but native language response I can do, but commands are impossible only working with HomePod.
thats my problem π
only if you have nonenglish speakers in your home
Yes.
ohhhh
I just hate those people who came into my place. I tell to google turn on the lights.
Ahh you have a smart home? and it cant speak hungarian? then why you do this, its worth nothing then.
happened already twice π
i totally get that hahaha
makes me sick π
i tell those people to stop being backward nationalists and to be glad its not in chinese
looool
agree π
we live close by, its a similar mentality
anyhow I hope google will do this sometime, it just a plus feature, what I would use.
where are you from?
ah nice country, we are really close then right π
my Idea was to go holiday to croatia, but the virus stuff solved that problem π π π
you should both move to the USA. you can stay in my house
other countries didn't mind π
no thanks π i prefer a safe country like syria
not really but its a running joke here sadly
I always think to that video when somebody doing smart home in the USA. https://www.youtube.com/watch?v=M8d5Wr9au9I
best smart home stuff ever.
even the music turn on some badass music and the light delay is perfect π π π
do you have any idea how much those guns would have cost lol
Yeah I'll go to the local tesco and use 10 bucks kid weapons for 5 year old kids.
Apple watch didnt refreshed since 35 minutes π¦
Ah I started home assistant and refreshed
so 30 minutes is real,but need manual start to refresh
any tips to make it look pretty and compact :D
https://paste.ubuntu.com/p/pHr7fr7dqb/
i can't think of a way to reduce that logic
i see why you did it. I'm not sure if that's the best way to go about it, but it would work
You could also create a separate sensor for corrected elevation which uses sun.sun elevation and subtracts 1 is it's cloudy and an additional 4 for winter, 3 for autumn etc. And then use that new sensor to determine your corrected sunrise.
Can someone tell me why this sensor isnβt updating with the current value for now()?
ac_last_changed:
friendly_name: 'AC Last Changed From Present'
unit_of_measurement: 'seconds'
value_template: >-
{% set CONTROL = 'sensor.be469zp_connect_smart_deadbolt_access_control' %}
{% set CONTROLlc = states.sensor[CONTROL.split('.')[-1]].last_changed %}
{{ as_timestamp(now()) - as_timestamp(CONTROLlc) }}
The value for CONTROLlc is static, but now() is changing constantly, so the template sensor should change. But itβs not
now() doesn't trigger a sensor to update. you need a datetime sensor
Is there such a sensor?
@surreal ether you commented on the forums on something similar. What Iβm trying to do is to create a sensor which returns the number of seconds a control has last been updated from the current time.
ac_last_changed:
friendly_name: 'AC Last Changed From Present'
unit_of_measurement: 'seconds'
value_template: >-
{% set CONTROL = 'sensor.be469zp_connect_smart_deadbolt_access_control' %}
{% set CONTROLlc = states.sensor[CONTROL.split('.')[-1]].last_changed %}
{{ as_timestamp(now()) - as_timestamp(CONTROLlc) }}
Now this wonβt work because apparently I need to use a datetime sensor to calculate what βnow()β should be. Do you have any ideas on how to write this sensor? I pinged you on the forum thread.
looking at it, that seems kinda dumb
{% set CONTROLlc = states.sensor.be469zp_connect_smart_deadbolt_access_control.last_changed %}
which might get around the problem on its own whenever that value updates
creating an extra var that doesn't need to be there
you'll have to link the forum post, I don't recall. Only place I'm using now() is for a history_stats sensor
especially since you immediately toss away part of the value
Hey! Any tips on how to make a cover template for a garage door with a switch that both opens, closes and stops the garage door motor. I have connected a binary sensor to monitor if port is open or closed
Maybe you could keep the current state in an input_select? It probably won't be very reliable, though.
I.e. opening/closing/stopped.
hmm, I'll look into it, thanks
Am I just bad at finding it, or is there no way to specify that if binary sensor has certain state, then cover should be considers as opened/closed
You'd set the value template to true or false https://www.home-assistant.io/integrations/cover.template/#value_template or open or close
E.g with value_template: "{{ states('binary_sensor.door_open') }}"
So I have to build a template first, correct?
oh! got it working, thanks a bunch @charred dagger !!
You could also create a separate sensor for corrected elevation which uses sun.sun elevation and subtracts 1 is it's cloudy and an additional 4 for winter, 3 for autumn etc. And then use that new sensor to determine your corrected sunrise.
@marble jackal thank you, actually good idea
I'm not sure if this is the right place to ask, but I'm trying to set the name of a button depending on the state of a sensor, I have the jinja code figured out, but how do I add it to the name part of my button? https://hastebin.com/jozadineni.cs
@quasi glade you are likely going to need to use something like https://github.com/custom-cards/button-card to achieve what I think you are asking for. At which point that conversation would need to move over to #frontend-archived if you decide to go that route.
Thanks, I'll try out the button-card instead π
I thought it might be possible using {{}} or something and I was simply doing it wrong
I have a temperature sensor and a card that shows temperature history. Is there a way to use templates to derive a new "sensor" that computes rate of temperature change?
Even a crude method that would use a single point in time, say 1 hour ago, as T_0 and the temperature now as T_1 so I could display (and plot) (T_1-T_0)/1 hour in degrees per hour.
@inner quest most people just use something like grafana for that
once you need to start accessing past states of a sensor things get tricky
So, can grafana access past states? I'm on a docker install of HA so no add-on support. I'm sure there is a way to install grafana but before I go down that rabbit hole I want to know it will do what I need. By the way, where is HA storing past data such that it can show me the history of the sensor? I'm looking to access that data.
Oh...I see it is in an sqlite DB! Maybe I can find what I need there
it stores it in a database much like how you would do to have grafana to utilize past records.
hmmm...seems like grafana wants influx DB...but HA already has the data in sqlite. Two copies of the same data in two different DBs? That seems strange (but I'm a total newb so I don't know didly squat)
that was written in 2018 so keep that in mind, but it's a good reference and should be good for the biggest part
Ok.
@surreal ether did you ever get a chance to look at https://community.home-assistant.io/t/different-results-in-template-vs-sensor-output/225797?
i don't have anything to add besides what was previously mentioned. you need to use the date time sensor.
Thatβs what I donβt understand. How do I include it into my sensor, much less consume it
gives an example
the resolution of sensor.time seems to be one minute though, so it might not work for you
if you need a finer resolution, i guess you might have to use the automation example, or re-work your original automation in some way.
Yeah, 1 minute is not working for me
I am in situation when sometimes the electricity is shut down several times and causes my bulbs to turn on same as restart Raspbery with Hassio. Any template to check which devices on when nobody home and send notification?
@final parcel you will want to do an automation for that
@bitter atlas yep, but it cannot be based on state change. Imagine scenario Electricity OFF > ON > Bulb ON and Raspberry starting > 3 min Home assistant ON > Automation based on state change of Bulb from OFF to ON will not trigger since the ON is from the start of Home assistant
@final parcel you can use HA start as the trigger and conditions to check state of bulbs
automation will fire once ha is fully started
if the same thing happened every single time you could just have it set the bulbs to what you wanted even if by chance their states weren't updated in HA
Thanks! Yep and thats the second scenario the state might not be update with the start, so how to solve that?
@surreal ether using an automation to update the sensor every second works
Not the most efficient solution, but whatever
@final parcel well you could always add a delay to the actions to give it more time along with a condition to check if any change
thats right
I wouldn't go crazy with the delay, but it shouldn't take too long to update the states if they weren't updated already
And second question.. How to filter out "Home assistant started" in history log? π
can't help ya there
@final parcel I added a condition to every automation, script, sensor, etc. that requires an input boolean to be enabled in order for it to be fired.
Pain in the neck, but it ensures βjunkβ doesnβt fire
Quick question. I use value_template: "{{ states.binary_sensor.shellyflood_heating_room_flood.attributes.battery }}" to extract the battery state from my flood sensor. The problem is that the battery state binary_sensor.shellyflood_heating_room_flood is listed not as a value, e.g., 100, it is listed in percentage, e.g., 100%. The percentage sign causes problems with the Battery State Card Addon. How can I remove the %?
{{ state_attr('sensor.shellyflood_heating_room_flood', 'battery')|replace('%', '')|float }}
@dreamy sinew It seems to work. Thank you very much.
/join lock-manager
wrong box?
@sly thistle only mods/admins can add channels
Hello Community, I would like to add an attribute from my climate (current_temperature) to my graph on my dashboard as a sensor or somehow else I dont know.
This is the attribute list of my climate https://ibb.co/PmxsHCk
Would like to add here: https://ibb.co/8rp04hm
You'd need to create a template sensor to expose that attribute and then add that entity
some cards allow you to use attributes directly, but most don't
Ahh that sounds interesting, I'll look for that.
np, always happy to hear that folks have worked it out on their own
π best feeling
@inner mesa I tried it, I was able to add it but diddnt worked well, so I tried to add the celsius sign at the end maybe thats the problem but also not working.
It do it like that.
maybe attributes don't get a unit_of_measurement automatically, but you can specify it in the sensor definition. If you don't, you get a "timeline"
I think you want "C"
Yes
I found the whole list in teh code a while ago
I use celcius
Thanks, I'll be able to do it with this information.
Mission Completed. Working correctly.
alias: Netflix Forward 3 minutes
sequence:
- service: remote.send_command
data_template:
entity_id: remote.livingroom
command: |
{% for i in range(0, 9) %}
- forward
{% endfor %}
- delay: '00:00:01'
- service: remote.send_command
data:
entity_id: remote.livingroom
command:
- play ```
^ is not working. dev tool gives correct output for loop but actual script does not do anything. no errors in log. any help with this?
I wonder if this will work
"{{ ['forward' for i in range(0,9)]|tojson }}"
Probably not
Kinda figured
It would still output as a string
Which is probably why the original didn't work
I see.
yes. I am on 0.114
I heard about repeat, never actually used it. looks like this will work. Thank you!
alias: Netflix Forward 3 minutes
sequence:
- repeat:
count: "9"
sequence:
- service: remote.send_command
data:
entity_id: remote.livingroom
command:
- forward
- delay: '00:00:01'
- service: remote.send_command
data:
entity_id: remote.livingroom
command:
- play ```
^ this works. Thanks @buoyant pine and @dreamy sinew for help.
Cross-posting per Tinkerer's advice π I'm trying to integrate all media devices in one room into a single UMP. The Ikea Symfonisk speaker remains in a 'paused' state indefinitely, but I want it to go to idle/off so that control goes to the next child to the list.
It seemed that the easiest way around this might be to proxy the Symfonisk through another UMP with a state_template that overrides the state with 'idle' after the actual speaker remains in 'paused' for 3 minutes.
Strangely, the if-template works as expected in Dev Tools > Templates, but the exact same template gives the incorrect fail status after 3 minutes:
state_template: >
{% if (as_timestamp(now()) - (3 * 60)) > (as_timestamp(states.media_player.b3d_symph0.last_changed)) and is_state('media_player.b3d_symph0', 'paused') %}idle
{% else %}fail
{% endif %}
Tinkerer mentioned that templates update when the entities in them change state, and now() is not an entity so it wouldn't prompt an update. I'm not too sure I understand, but is the issue that only changes to the media_player.b3d_symph0 state will prompt an update, and therefore will always be within 3 minutes (or 0 seconds) of the last_changed value and therefore never work out to idle as I'm hoping?
I'm not too sure I understand, but is the issue that only changes to the
media_player.b3d_symph0state will prompt an update, and therefore will always be within 3 minutes (or 0 seconds) of the last_changed value and therefore never work out toidleas I'm hoping?
@bronze horizon more than likely
Ah, just found the docs about calling the homeassistant.update_entity service to get around this. Sounds like what I need, but am I gonna cause problems updating every few seconds?
no
Hello, needs some help with a template. I've got a tower fan that works off of IR to control the fan, I've installed a SP20 wall plug with Tasmota flashed to it. The wall plug can monitor power and current along with turn on and off through MQTT. The MQTT has set up sensors for the plug and I can see how much power the fan draws. What I would like to do is set up a template for a switch that returns the state on or off based on whether the plug switch is on and if the fan is drawing power above a certain threshold
what sensor content are you getting?
Energy Current and Energy power are what I'm looking at
power is in watts and current is in amps
right now the fan is on and its pulling 53 watts
do you need to parse the data coming from MQTT, or you already have the states you want?
already in a state that I want
I'm thinking some sort of IF
IE: if the power is = or > 50 watts the fan is on
ok, just trying to figure out if the fact that the data is coming from MQTT has any bearing on the solution. It seems not
but I also this it needs to check the switch state. If the switch is off, nothing is on
I've got a RM4 mini that I'll use to control the fan itself but I need to know the state before I send any IR codes to the fan
have you checked out the docs?
there are examples there that appear to cover your "IE: if the power is = or > 50 watts the fan is on" case
and you can use the same template in a template switch: https://www.home-assistant.io/integrations/switch.template/
I saw the switch template and I'm not sure how to implement it
so the washing machine running binary sensor does look like what I want
A template switch is pretty straightforward, with examples on the page. It's just an optional status, which is the same as the value_template that you'd use in a binary_sensor and service calls for on and off (whatever you need to publish to MQTT, probably via mqtt.publish)
np
here's one of mine:
switch:
- platform: template
switches:
downstairs_lights:
value_template: "{{ is_state('group.downstairs_lights', 'on') }}"
turn_on:
service: homeassistant.turn_on
data:
entity_id: group.downstairs_lights
turn_off:
service: script.turn_off_downstairs_lights
got it working
the binary sensor docs did it.
now I just need to get the state from the plug faster then every 5 min
Good job! Youβll probably want #hardware-archived for Tasmota issues. Or their discord server
I seem to remember reading about it I just have to find that blog
just occurred to me that if I know the watts I can create a sensor to tell me if the fan is on low, med, or high.
Sure
now if I can make a switch that will do the laundry I'll be set
Fluff and fold is the tricky bit
HA
Why does this not work?
entity_id: "light.livingroom_window_1" brightness: "0" transition: "{{ range(1, 20)|random }}"
post the rest of it
I think i did it right now, the problem must been the int
day: sequence: - service: light.turn_on entity_id: light.livingroom_window_1 data_template: brightness: 0 transition: '{{ range(1, 20)|random|int }}'
Cause now it looks like it works. Thanks anyways! π
Also the problem with the entity id in data_template
although in all mine i have entity_id under data_template
is that its turn off the lamp and turn on and then change transition as i see from the ui cause im not in the house rn
never tried it like that but if it works, whatever
i would use a scene for that function
not the light.turn_on service. i'd use scene.apply and set the transition there
I cant do the range there?
you should be able to do the range template with scene.apply or scene.turn_on if you want to pre-define it
How do you mean?
You mean i can do like?
``
- name: Day
entities:Livingroom
light.livingroom_window_1:
state: true
brightness: 0
transition: '{{ range(1, 20)|random|int }}'
``
day:
sequence:
- service: scene.apply
data_template:
entities:
light.livingroom_window_1:
state: "off"
transition: '{{ range(1, 20)|random|int }}'
i think that will work.
What would i gain of that?
I mean i wont the lamp to be on 0 brightness on next turn on
wait, you want to turn it on, or off?
off but next time i turn it on i want it to have 0 brightness
but then it would be off, right?
correct. but why would you want it to have 0 brightness next time?
Cause in norning when i then do a light turn on with transition and brightness at like 50 it maybe sets to 255 if it last state was that am i right? and then it decrease to set brightness
Which maybe woke me up before it should
i see
then in that case i'd use the same service to turn it back on in the morning.
day:
sequence:
- service: scene.apply
data_template:
entities:
light.livingroom_window_1:
state: "on"
brightness: 100
transition: '{{ range(1, 20)|random|int }}'
you don't have to do it that way, but it would work.
Would it? It would been last state and then decrease or increase until 100?
With that transition
I want it from 0 and then to 100 in that case
no, if it is off and then you apply that scene with a transition, it will go from off to 100
it works differently than the light.turn_on service.
at least that is my experience.
I can try π
worth a shot
It goes from last brightness to 0 then up
And both down and up has the transition
π¦
How does your look?
just like I said
Weird then
maybe do the scene call the way you had it before my advice.
day:
sequence:
- service: scene.apply
data_template:
entities:
light.livingroom_window_1:
state: "on"
brightness: 0
transition: '{{ range(1, 20)|random|int }}'
Yea but then its weird cause it turn off lamp in ui then turn on and decrease it to 0 so yea
who cares about the UI tho?
all that matters is the behavior of the actual light, right?
Yea but im not in the house so i cant see
oh ok.
But!
if you want it to be off in the ui just add a delay then use light.turn_off after 20 seconds
I may can do a script i call in every script that sets everything to 0
Btw it works exactly like before but with random delay with your setup thanks! @violet oyster
I have no clue. Can i do like a script with a array like calling it with attribute ``to: [person1, person2, person3] and all these objects have a seperate action in one script?
yes, with the choose function
Can i? Does it go thru 3 actions if them all are true?
Like can i have a if, if, if there?
theoretically yes, youd just have to make a bunch of differerent chooser conditions for each possible combination
Ok can you maybe explain how i get the array into there?
Like can i even get a choose into a script?
look for "Automations & Scripts: Chooser"
then for the condition use a template condiiton
But that wont work? I mean like i want to merge these
https://pastebin.com/J3yUZyvv
with one script that i can call with a attrubute like to: [person1, person2] or maybe only [person2] or [person1]
yeah you can merge them using the chooser. take the condition out of the script and use that as the chooser condition. then put the service in the chooser sequence
But can i call multiple ifs at same time?
what do you mean by ifs
if -> then multple of these to be called same time based on variable
this goes for both automations and script https://discordapp.com/channels/330944238910963714/672220450977349653/754667024466313246
condition:
condition: template
value_template: "{{ if is_state('input_boolean.notify_person1_discord', 'on') and is_state('input_boolean.notify_person2_discord', 'on'), True }}"
if thats what you mean
No not really i cant explain xD
instead of calling mulitple scripts in automations for sending same message but to different persons on different conditions i want to call one script with a variable called "recievers" and value is maybe [person1] or [person2]or [person1, person2] then send the message to these persons defined there with different conditions and actions
I would create a really complex template sensor to handle all the if's and output specific state at which an automation/script can be more easily constructed to follow without it being a complete nightmare
Can you give me a example of that?
an example of a nightmare? uh no lol i wouldn't evven want to try and type that out lol
haha, i can. for my hvac automation
@bitter atlas no but for how you see a solution of this
Cuz i have multiple automations that have the action to send message but maybe with multiple recivers or only one
you have all the entities in place to handle the different conditions right? well a template sensor can take those and compare then and then spit out different custom states based on the condition you set
yea like that what @violet oyster posted
i hate it lol
I will explain more
That isnβt a valid template, though
what isnt? mine?
Yes
how so? it works
If xxx and xxx, True?
oh i thought you meant my pastebin one
Sorry, the one above
A bunch of blocked messages are causing me to miss the context. Iβll step away... π
oh i don't need the if for the one you are saying
Here is a more depth explain in my case ig https://pastebin.com/3MWdsRtn
Or the comma, or the True
haha i typed it up on the fly. fuck me
@vagrant monolith like @bitter atlas said i would use a template sensor for that and 12 different scripts for all the different combinations of people who might need to be notified. or one script with 12 different chooser conditions.
would be close to the same lines of code either way.
or just keep it like you have it since that doesn't seem too bad.
Would it be a template that saves the last sane value? My weather keeps going "unknown" and I'd like to just save the last known good until it comes back.
@thorny snow I would create a template that copies the value except when it is unknown. That should keep it up to date with the last know value
Am I going about this the right way? (not tested this code yet)
I'm trying to map the indoors temperature to a value between 0-255, this is the template i've written: https://hastebin.com/naxififoyu.cs
Hi all! i have a quick question related to a simple problem
i'm adapting a template to calculate vapor pressure deficit
@dusky bane posted a code wall, it is moved here --> https://paste.ubuntu.com/p/hXkkHDq3Yp/
it gives an error i believe from {% set LT = states('sensor.leaf_temp') | float %}
it's an input_number really, i tried different methods to use this number i set in a box or a slider but don't figure it out
so my question is , how can i refer to a slider or box in a template ?
here is the input_number :
'''
input_number:
leaf_temp:
name: Leaf Temp
initial: 0
min: -10
max: 0
step: 0.5
mode: box
'''
sorry i don't remember how to format the text to yaml
To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks. Here's an example:
```
code here
```
Watch the animated gif here: https://bit.ly/2GbfRJE
DO NOT repeat posts. Please edit previously posted message, here is how -> https://bit.ly/2qOOf1G
wrong quotes
okay thx
it looks like you defined input_number.leaf_temp and are referring to it as sensor.leaf_temp?
that would be incorrect
you need to refer to it by the actual name π
does it work in
-> Templates?
"various ways" for sure won't work
what error are you getting?
i'm trying stuff in developper tools indeed but right now i'm confused sorry, thank you for the input, i come back eventually with a clearer problem π
ok i think i get it working, my problem were syntax and mathematical and confusion, thank you for help anyway
when you say i need ti refer to it by the actual name
input_number:
leaf_diftemp:
name: leafdiftemp
initial: 0
min: -10
max: 0
step: 0.5
mode: box
i should refer to state('input_number.leaf_diftemp') or state('imput_number.leafdiftemp') or any other syntax ?
the first one
the name: is for display
always check
-> States for what things are called and their states/attributes
in all cases, refer to entities by their entity names, as shown in the first column
okay thank you for your guidance i got it working
Hi all
@honest mauve posted a code wall, it is moved here --> https://paste.ubuntu.com/p/M8VYMN949R/
I Have this error
- platform: template
sensors:
lavastoviglie_tempo_residuo:
friendly_name: "Lavastoviglie - Tempo Residuo"
unit_of_measurement: ' min'
value_template: "{%- if states.sensor.lavastoviglie_remaining_program_time.state != None -%}
{{((as_timestamp(states.sensor.lavastoviglie_remaining_program_time.state)-as_timestamp(now()))/60) | int }}
{%- else -%}
0
{%- endif -%}"```
That's my sensor
I check if it's None
but it seems not to work
how can I fix it?
Hi all! I try to formulate a condition to activate action if value goes below or above 1 and 1.45 :
condition:
condition: or
conditions:
- condition: template
value_template: {{ (states('sensor.vapor_deficit') | float < 1) }}
- condition: template
value_template: {{ (states('sensor.vapor_deficit') | float > 1.45) }}
i don't understand the error :
``
invalid key: "OrderedDict([("(states('sensor.vapor_deficit') | float '< 1')", None)])"
someone can enlight me ?
oh okay forget it
It happens sometime i try to figure out something for hours and when i ask for help i find the solution in the next minute
add .state at the end
use [] instead of ()
states['sensor.vapor_deficit'].state
@dusky bane does it work?
thank you for your input @honest mauve i just forgot "" like that : "(states('sensor.vapor_deficit')" and it was solved
"{{ (states('sensor.vapor_deficit') | float < 1) }}" i mean
ok
I Have this error : https://paste.ubuntu.com/p/M8VYMN949R/
- platform: template
sensors:
lavastoviglie_tempo_residuo:
friendly_name: "Lavastoviglie - Tempo Residuo"
unit_of_measurement: ' min'
value_template: "{%- if states.sensor.lavastoviglie_remaining_program_time.state != None -%}
{{((as_timestamp(states.sensor.lavastoviglie_remaining_program_time.state)-as_timestamp(now()))/60) | int }}
{%- else -%}
0
{%- endif -%}"
That's my sensor
I check if it's None
but it seems not to work
how can I fix it?
I've found a template online that should calculate the percentage of a timer. I still don't understand templates a lot, could someone tell me which parts I need to change to my own timer? (timer.ledtimer){% set timer = 'xxx' %} {% if is_state('timer.'~timer,'active') %} {% set state = states.timer[timer] %} {% set dur = state.attributes.duration.split(':') %} {% set dur = ((dur[0]|int)*60+dur[1]|int)*60+dur[2]|int %} {{ ((now() - state.last_changed).total_seconds()/dur*100)|int }} {% else %} 0 {% endif %}
@fierce hornet the xxx part at top. Set it for what is after timer.
so if you have a timer.super_timer you would change 'xxx' to 'super_timer'
ahh, thank you!
i'm in the same kind of work now, i try to limit notifications to a certain time, because i receive it every minute
so this is the condition for the automation that sends the notification :
- condition: template
value_template: "{{ states('sensor.vapor_deficit') | float < states('input_number.vpd_min') | float }}"
after trying different stuff i have no result
i would like to add to the template that the result have to be true for a certain amount of time
do i have to use the same kind of timer methods or there is a shortcut ?
Use for:
Hmm, if that works for a template condition
Worst case, create a template sensor and a state condition with a for:
yes i tried a bit with for: but seems not intended to work in a template
i don't see how i can solve this with a template binary sensor, can you elaborate ?
Use the same template that you have there in a template binary sensor. The value will always be on or off
Then use a state condition based on that sensor with a βfor:β clause
okay never use this way i will try it thank you for the idea
Itβs just a roundabout way of doing a template with a for:. Maybe Iβll post a WTH about it
Well you would need to track the state of a template to use for. Not sure how else you would do that without a sensor
i think i have something not sure if its working well but dont give error at least :
binary_sensor:
- platform: template
sensors:
vpd_min_state:
value_template: >-
{{ states('sensor.vapor_deficit') | float < states('input_number.vpd_min') | float }}
delay_on: '00:00:10'
yeah, or you could do that. I keep forgetting about the "delay_x*" options
yes i allways check the website documentation because im 0% autonomous because i'm new and then i found that
anyway thank you you put me on tracks
HI, i have a weird problem
i got this script: https://pastebin.com/aLL4Gwn8
every second time i call this script it wont turn my lights on, if i turned them off. no matter how long i waited etc. if i delete the template from the script everything works fine. someone has a clue?
is someting wrong with my template?
yes, this:
brightness_pct: "{{ state_attr('switch.circadian_lighting_fl', 'brightness') | int }}"
``` should be this:
brightness: "{{ state_attr('switch.circadian_lighting_fl', 'brightness') | int }}"
@young jacinth
brightness gets reported in pct from circardian lighting. this does not solve my solution as the issue stays anyway
oh, my bad
https://pastebin.com/4Dkg2HGW
if i change up the script like this, everything works. so the connection to my lights should be fine
I'm getting an error on my template: https://paste.ubuntu.com/p/NBZwD36Qnd/
What does the template render as in dev tools?
Oh I've never used taht feature, do I just paste my template in there?
yup
I'm getting Unknown error rendering template
You're using is_state incorrectly
just use states for what you're trying to do
{% if states('sensor.temperature') | int < 18 %}
0
{% elif states('sensor.temperature') | int > 28 %}
255
{% else %}
{{ states('sensor.temperature') |int - 18 | multiply(25.5) }}
{% endif %}
Thank you!
This template render is a game changer! What an awesome feature
I'm trying to map the states('sensor.temperature') values between 18Β°C and 28Β°C to values between 0 and 255, but I'm having trouble figuring out the best approach to do this.
Ok folks, why is this rendering false? https://imgur.com/WnrC7AU
you need to filter the state values if you want them to be numbers
states are strings
so use |float
I use basically the same template in two automations. One has a > and the other has a < The template with the > renders correctly even without |float or |int
I was testing option in the template tool and tried |int first which works for me. |float does as well. I think I am going to keep with |int as it add some cushion to the on/off of the automations. (going from 100F to 99.9F and back to 100F doesn't turn the switch on/off/on again. )
Thanks for the help.
np
I'm trying to control a light that wants an int between 0-255, but somehow what I'm sending isnt an int?? https://paste.ubuntu.com/p/mK5kvnqYht/
It sure looks like an int in the template renderer
Oh I see
hahaha i'm one of the last few who came across this error then
congrats
It's working now! Thanks for all the help
I have this template that lists name, name, entity, entity. How can I make it show name, entity, name, entity? {{ state_attr('sensor.utilgjengelige_entiteter','names').split(', ') | join('\n') }} {{ state_attr('sensor.utilgjengelige_entiteter','entities').split(', ') | join('\n') }}
Did that make sense? π
Would that do the trick? :
{% set names = state_attr('sensor.utilgjengelige_entiteter','names') %} {% set ents = state_attr('sensor.utilgjengelige_entiteter','entities') %} {% for nm in names.split(',') %} {%- set pos = names | regex_replace(nm+'.*', '') | regex_replace('[^,]', '') | length -%} {{ nm }} {{ ents.split(',')[pos] }} {% endfor %}
hypothesis to make this work, the names should be unique
{% set l2 = ["e1", "e2"] %}
{% set ns = namespace(things=[]) %}
{% for i in range(l1|length) %}
{% set ns.things = ns.things + [(l1[i], l2[i])] %}
{%endfor%}
{{ns.things}}```
output
[('n1', 'e1'), ('n2', 'e2')]
Cool, didn't know about that range function
Then my version (if you work with strings and not collections) would be
{% set names = state_attr('sensor.utilgjengelige_entiteter','names') %} {% set ents = state_attr('sensor.utilgjengelige_entiteter','entities') %} {%- set size = names | regex_replace('[^,]', '') | length +1 -%} {% for i in range(size) -%} {{ names.split(',')[i] }} {{ ents.split(',')[i] }} {% endfor %}
the results of those things are just strings right?
lists of strings?
state_attr('sensor.utilgjengelige_entiteter','names')|list
what is the raw output of :
state_attr('sensor.utilgjengelige_entiteter','names')
hi there people. Need a litle help. My ceiling have 13 gu10 rgb 6w bulbs that use tuya. Can anyone help me to create color cenes for tham, lke raibow for that group.
@desert quail you should google around and even check out the forums. https://community.home-assistant.io/ I am sure someone has done something that will point you in the right direction on how to do what you want
@bitter atlas already try that, but, i think I dint use the right querie :S
The raw output of that is 'Gang - Range extender, OPPLE switch 2-gang Battery Level'.
ok, state_attr('sensor.utilgjengelige_entiteter','names').split(', ')
that'll get you a list that you can then directly use
Uhm. I see I explained poorly. I would like a string saying: name1 (entity_id 1) name2 (entidy_id 2)
The latest output from slashback was pretty close. That shows:
Gang - Range extender
light.range_extender_5
OPPLE switch 2-gang Battery Level
sensor.opple_switch_2_gang_battery_level
{{ '{} ({})'.format(names.split(',')[i], ents.split(',')[i]) }}
{% endfor %}```
taking from @deft timber 's line above
OPPLE switch 2-gang Battery Level ( sensor.opple_switch_2_gang_battery_level)```
Where does the space in front of second line come from? And the space after the 2nd line first (
No change
do {{- on the output line
Like this? No change. {%- for i in range(size) -%} {{- '{} ({})'.format(names.split(',')[i], ents.split(',')[i]) }} {% endfor %}
Strange. I tried
{% for i in range(size) -%} {{ names.split(',')[i] }} ({{ ents.split(',')[i] }}) {% endfor %}
and it works
a (n1) b (n2) c (n3)
i wonder if you have an extra space in your lists and that was getting caught
I checked the attributes of the sensor and it's like this: entities: 'light.range_extender_5, sensor.opple_switch_2_gang_battery_level' names: 'Gang - Range extender, OPPLE switch 2-gang Battery Level'
because i wasn't able to repro with my test
ok you have a space after the ','
Yeah, I see
Eyy.. this worked {{ names.split(', ')[i] }} ({{ ents.split(', ')[i] }})
I did it with
{% for i in range(size) -%} {{ names.split(',')[i] | regex_replace('^ *','')}} ({{ ents.split(',')[i] | regex_replace('^ *','') }}) {% endfor %}
byt phnx proposition is prettier
the "clean code" guy in me says you should split the list when you create it vs doing the split on every loop
+1
post the full thing real quick?
The one that worked was this {% set names = state_attr('sensor.utilgjengelige_entiteter','names') %} {% set ents = state_attr('sensor.utilgjengelige_entiteter','entities') %} {%- set size = names | regex_replace('[^,]', '') | length +1 -%} {% for i in range(size) -%} {{ names.split(', ')[i] }} ({{ ents.split(', ')[i] }}) {% endfor %}
yeah
I'm gonna take your advice though and modify the sensor to show it without spaces
Maybe π
{% set names = state_attr('sensor.utilgjengelige_entiteter','names').split(', ') %}
{% set ents = state_attr('sensor.utilgjengelige_entiteter','entities').split(', ') %}
{% for i in range(names|length) -%}
{{ '{} ({})'.format(names[i], ents[i]) }}
{% endfor %}
Oh thats what you meant "when you create it". I thought you meant in the sensor.
there, final edit
Thanks a bunch
one less var. The output is "messier" in some regards but i like this method better because i day-job python
too bad jinja2 doesn't do fstrings
and if you decide you want to change the format, it is a bit easier
since you can leave the .format() bit alone and just add stuff to the string
I'm repost my question now since quackeds seems to be solved π
Hey everyone! So I'm wondering how I could go about calculating total space left on my unraid server. I have all my hard drives used & free values in home assistant already but I don't have a value that shows the total space left/used across them all. Is there a smart way to create this?
@wicked temple https://www.home-assistant.io/integrations/systemmonitor
total space as in all drives added together?
I'm already getting "used" and "left" values from each individiual drive
Yeah exactly!
Its a matter of just calculating the sensors together, i just don't know how to do that
"math" π
you would just create a template sensor with something like this "{{ states('sensor.something') | float + states('sensor.whatever') | float }}"
another "+"
states('xxx') is the state as a string, |float turns it into a float that can be used in mathematical expressions, + does the adding
{{ states('sensor.diskstotal') | float + states('sensor.glances_mnt_disk1_used_percent') + states('sensor.glances_mnt_disk2_used_percent') + states('sensor.glances_mnt_disk3_used_percent') | float }}
So something like this?
I'm sorry I'm really crap when it comes to this, I'm not sure I understand π
{{ states('sensor.glances_mnt_disk1_used_percent') | float + states('sensor.glances_mnt_disk2_used_percent') | float + states('sensor.glances_mnt_disk3_used_percent') | float }}
don't do it phnx!!
{{ [states('sensor.glances_mnt_disk1_used_percent'), states('sensor.glances_mnt_disk2_used_percent'), states('sensor.glances_mnt_disk3_used_percent')]|sum }}
and presto, we got blessed by a templating God.. i need a shower
Unknown error rendering template
Can't I use it it in the Template thingy under Developer tools?
yeah, its trying to math strings and bails
cast them all to floats and it'll work
Thatβs totally better π
Not average, I want the total amount of disk space left
Wait im dumb
Yes, I can use this formula
oh, these are percentages
Just need to pick the right sensor haha
any way to use the used and total values directly?
messing with percentage values won't be fun
Yeah I have these for each drive sensor.glances_mnt_disk2_free & sensor.glances_mnt_disk2_used
They're just numbers in GB
do you have total size?
oh, don't need it
just add up free and you're done
unless you want percentage and then you'd need to add a bunch of stuff
Whatever way is the easiest to implement i'm all for it
what do you want to see as your end result? GB free or % available?
do you have a total size output for each disk?
Actually scratch that, GB free is much better for me
I only have those 2 values for each disk
ah, that's a pain
but just add up GB Free and be done with it
using the template from above, swap in the _free entities and you'll have your number
add a unit of measurement of GB and you're golden
Works great! Thanks alot π
@dreamy sinew π
Lol
I'm having trouble with my template, it worked for a bit but now it doesn't. It is supposed to read the Google calendar and turn off accordingly.
- condition: template
value_template: '{% if now().year~''-''~now().month~''-''~now().day~''-''~now().hour~''-''~now().minute~''-''~now().second
>= state_attr(''calendar.ouachita_hills_academy'',''start_time'') and now().year~''-''~now().month~''-''~now().day~''-''~now().hour~''-''~now().minute~''-''~now().second
<= state_attr(''calendar.ouachita_hills_academy'',''end_time'') and is_state_attr(''calendar.ouachita_hills_academy'',''description'',''class
off'') %}{{false}}{%else%}{{true}}{%endif%}'
Thanks
today it should be on but tomorrow it shouldn't. Here is what is in states.
message: Vocational Classes
all_day: true
start_time: 2020-09-16 00:00:00
end_time: 2020-09-17 00:00:00
location:
description: class off
offset_reached: false
friendly_name: Ouachita-Hills-Academy
if you paste that into the template editor it does not work?
@calm kettle I'm not sure where you are from either, but today is the 15th for me. And your calendars time's are for tomorrow
yes today it should be on. and tomorrow it should be off. The bell is on unless otherwise told not to be.
What is your date today?
the problem is that it is not turning off when its supposed to
I'm in Arkansas today is the 15th
Ok, well your calendar event says tomorrow
start_time: 2020-09-16 00:00:00
end_time: 2020-09-17 00:00:00
so it's not your template
yes, I'm trying to fix it today so that it will not turn on tomorrow
the date for the calendar is correct
It's been a problem I've been remedying by just turning off the automation.
calendar entity or your actual calendar outside HA
This is what I'm confused about: You say it should be ON today, but the dates on the calendar entity are for tomorrow, and you say the calendar is correct
so what's correct
that is what it is showing in the states, it always shows the next calendar event.
I see the confusion.
the bell is always set to turn on
everyday
Ok, so it should be OFF today
the only thing that stops it is when it checks the calendar to see if it is supposed to be off
no, today the bell should be on
I'm trying to fix the problem I will have tomorrow.
Ok, so you want to check a day ahead then, but it should be off tomorrow
I just create templat binary with something like is_state_attr('calendar.holidays_in_united_states', 'message', 'New Year\'s Eve' and then use that as a condition.
yes
I just create templat bools with something like
is_state_attr('calendar.holidays_in_united_states', 'message', 'New Year\'s Eve'and then use that as a condition.
@bitter atlas hum... I thought I did...
off'') %}{{false}}{%else%}{{true}}{%endif%}'```
I thought what you posted above was in like an automation or something. plus it's very complex when all your checking is if it's that day
first, you should incorporate
sensor:
- platform: time_date
displayed_options:
- date_time
yeah, it happens when you don't know what you are doing....
lol
I'm still having trouble writing things out correctly lol
ok let me give it a shot.
{% if is_state_attr('calendar.ouachita_hills_academy', 'description', 'class off') %} should work in a bool
Then use this as your value_template, easier to read:
value_template: >
{% set t = state_attr('sensor.date_time', 'timestamp) | timestamp_custom('%Y-%m-%d %H:%M:%S') %}
{% set start = state_attr(''calendar.ouachita_hills_academy'',''start_time'') %}
{% set end = state_attr(''calendar.ouachita_hills_academy'',''end_time'') %}
{% set class_off = is_state_attr(''calendar.ouachita_hills_academy'',''description'',''class off'') %}
{{ start =< t <= end and class_off }}
But that will not check tomorrow, that will only work day of. So if the event's are always shown ahead of time, you'd need to add 24 hours (in seconds) to t
which looks like:
value_template: >
{% set t = (state_attr('sensor.date_time', 'timestamp)+86400)| timestamp_custom('%Y-%m-%d %H:%M:%S') %}
{% set start = state_attr(''calendar.ouachita_hills_academy'',''start_time'') %}
{% set end = state_attr(''calendar.ouachita_hills_academy'',''end_time'') %}
{% set class_off = is_state_attr(''calendar.ouachita_hills_academy'',''description'',''class off'') %}
{{ start =< t <= end and class_off }}
ok sweet, It's still booting π©
humm.. I may have bigger problems if it doesn't boot...
That will only work if you add sensor.date_time. If you're keeping this a condition and not a template sensor, you don't need sensor.date_time
well it's not booting... I'm pretty sure it is because I have a crappie budget SD card. I bought a Samsung card that I was about to image to and now it may be too late. I did save the config, so I'll just use a stock image and upload my config.
Thanks for the help, I'll have to come back later and tell you how it went.
the good news is that the bell will be off tomorrow π
that's true lol
Hi, looking for some help. I'm trying to calculated the total time configured per week day configured. If the entity (input_number) is configured for a specific day, it is added a group for that day of the week. How can I loop through the members of the group and sum their values?
i've seen some tricks but i don't have any groups so i don't remember them
Thx! Found a basic example on the forum to print the entity_ids - Will try and build from there.
it gets tricky if you're trying to do a sensor
The idea is to do the calculation at runtime and display the result on a lovelace card
if you're cool with a button press to do the calculation you're golden
homeassistant.update_entity would be the service to call
Thank you so much! This is so much more elegant than what I have been busy creating...
just as long as you're cool with the caveat that it will never update on its own π
oh wait
{{ [states(x)|float for x in state_attr('group.your_group', 'entity_id')]|sum }}
sorry, need to make it a number otherwise it will puke
should be able to drop it in the template tester though
If I am getting this error Error executing script. Unexpected error for call_service at pos 2: 'entity_id' would service position 2 include only - service or would it be the 3rd - under the sequence?
.share the full thing please
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
When I use this under dev tools - templates I get a line shift after each item, but when I add it to an persistent notification automation there is no line shift. Any ideas? {% set names = state_attr('sensor.utilgjengelige_entiteter','names').split(', ') %} {% set ents = state_attr('sensor.utilgjengelige_entiteter','entities').split(', ') %} {% for i in range(names|length) -%} {{ '{} ({})'.format(names[i], ents[i]) }} {% endfor %}
never messed with it. might be that the notification eats line breaks
Google says that {{ '\n' -}} should work. Can that be put into the above somehow?
{{ '{} ({})'.format(names[i], ents[i]) }} {{ '\n' -}}?
Trying it now
{% set ents = "another, word".split(', ') %}
{% for i in range(names|length) -%}
{{ '{} ({})'.format(names[i], ents[i]) }}{{ '\n' if i != names|length -}}
{% endfor %}```
sorry, had to add some dummy values since i don't have those entities
What's the i != names|length?
no extra newline at the end of the template
Ah. Thanks again π
here's the two scripts, I am on beta so service is correct (vs service_template)
i get the error when i run unpause_outside_cameras
and the only input_boolean that is 'on' is input_boolean.camera_frontporch
i can manually run enable_frontporch_camera and it works with no errors
but the error looks like that's the one it is complaining about
what error?
do you know which one it is complaining about?
that's what i was trying to confirm, i am assuming the error Error executing script. Unexpected error for call_service at pos 2: 'entity_id' when i run script.unpause_outside_cameras is refering to the 3rd - service which is the frontporch_camera
did you try each of those blocks in
-> Temp[lates?
yes
no errors, and expected results
here's the full error https://hastebin.com/bucobesika.sql
seems to have an issue with the is_state_attr?
in the enable_frontporch_camera but manually running that script works
quote the false
I would think not - if it's really a boolean
it almost never is though
I went through that yesterday with someone and it was
for sun.sun & rising
could be either, I guess
still, I would think the result would be the "else" case unexpectedly
{{ state_attr('camera.blink_frontporch', 'motion_detected') is boolean }} says True
PoPBoX with the skillz
let me jump back to 114.4 and see if this isn't a bug
aren't you missing the entity_id from homeassistant.update_entity?
this seems incomplete:
- service: >
{% if is_state('input_boolean.camera_mudroom_door', 'on') %}
script.enable_mudroom_door_camera
{% else %}
homeassistant.update_entity
{% endif %}
oh, yes it is
the script is just a service, but homeassistant.update_entity is expecting an entity
that's a problem twice
a choose would work there
waiting for my HA to load backup and i'll try with the entity_id added
You'll at least need to split it up
it all needs to be rewritten, it's highly unreliable
it does seem complicated
and it was just to bypass having to put in delays waiting for blink to arm/unarm cameras that were already in that state
Any idea while this is not working?```
{%- set total_time = 0 -%}
{%- for number in range(1,16,1) %}
{{ total_time + 1 }}
{% endfor %}
It just renders '1' - 16 times...
what are you expecting?
1,2,3,4,5 .... 14,15,16
also namespacing
{%- set ns = namespace(total_time=0) -%}
{%- for number in range(1,16,1) %}
{%- set ns.total_time = ns.total_time + 1 -%}
{{ ns.total_time }}
{% endfor %}```
since += isn't a thing sadly
it was the missing entity_ids for hte homeassistant.update_entity, thanks!
i wonder though
Thank you! ππΌ
seems weird that the dashes in {%- and -%} are required to avoid extra newlines in the output
if I remove them in {%- set ns.total_time = ns.total_time + 1 -%}, I get a bunch of extra newlines from what I would have thought is simply logic
isn't it just needed in {{- ns.total_time -}}
because the logic is evaluated but it still takes space
evidently
I never ever need or use a dash in my scripts/automations, so I don't know the rules
if you look through forum posts from ages ago, they're everywhere
{{ ",".join(range(1,16,1)|map("string")|list) }}
π
output: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
now code the answer to the meaning of life
{{ 42 }}
yessssss
i'm not sure how useful that output is, but its there
lol
xkcd 221
hahaha
try:
answer = self.answer_question("What is the answer to the ultimate question?")
except TimeOutError:
answer = 42
finally:
return answer
i wish they never made the movie. cheapens such an unbelievable book series
Hello I'm back again.
Got an error
Message malformed: invalid template (TemplateSyntaxError: unexpected '%') for dictionary value @ data['condition'][0]['value_template']
this is the template
{% set start = state_attr(''calendar.ouachita_hills_academy'',''start_time'') %}
{% set end = state_attr(''calendar.ouachita_hills_academy'',''end_time'') %}
{% set class_off = is_state_attr(''calendar.ouachita_hills_academy'',''description'',''class off'') %}
{{ start =< t <= end and class_off }}```
missing a ' after timestamp
also why are there double single quotes on the rest of them
the UI does garbage like that
oh
its technically correct but really ugly
thanks ui, i hate it
I'm still really bad at syntax, this code was given to me earlier by a helpful guy on here
I'm very much a noob at this and only have an into to programing class as a basis.
jinja is a bit special
Message malformed: invalid template (TemplateSyntaxError: expected token 'end of print statement', got '=') for dictionary value @ data['condition'][0]['value_template']
still getting errors...
{% set start = state_attr('calendar.ouachita_hills_academy','start_time') %}
{% set end = state_attr('calendar.ouachita_hills_academy','end_time') %}
{% set class_off = is_state_attr('calendar.ouachita_hills_academy','description','class off') %}
{{ start =< t <= end and class_off }}```
I changed it but might have made it worse
may be I need to read up on something. Like yaml for dummies? LOL
needs to be <=
Jinja
seems to have liked that.
damn missed that one. saw the first error and thought i cracked the case lol
Jinja
@inner mesa are you saying Jinja is a good place to start?
.jinja2 is a good place to start
Jinja is used by Home Assistant's template engine, see the Jinja Template Designer Documentation
Thanks for the help guys, I hope the system works like it should tomorrow.
https://jinja.palletsprojects.com/en/2.11.x/templates/
@violet oyster I was just on that site. ok I'll look into it. I still feel over my head, but eventually I hope it clicks.
humm... I have a problem now. the automation should work for today but not tomorrow. and now if I set it to go off for today it's not doing it.
I think it is because in the states it shows the next event no matter how far in the future.
it says its 'off'
message: Vocational Classes
all_day: true
start_time: 2020-09-16 00:00:00
end_time: 2020-09-17 00:00:00
location:
description: class off
offset_reached: false
friendly_name: Ouachita-Hills-Academy
wait. what are you trying to do
I have a relay I need to trigger on a schedule, I want it to trigger everyday except when told not to by the calendar.
for instance today it should ring
tomorrow it should not
sorry I said ring but trigger is what I meant. It is for a class bell
you need it to trigger at a specific time only once?
repeating every week
so the trigger is the time of day and the condition is the calendar
if I'm saying that right.
everyday if the condition is not met, in this case 'class off' the bell will ring.
so, i'm no expert here, but i am wondering about the template syntax with
{% set class_off = is_state_attr('calendar.ouachita_hills_academy','description','class off') %}
wouldn't that set class_off as 'true' or 'false'? and if so, wouldn't the final line need to condition class_off to be either true or false instead of just reference it?
like
{{ start <= t <= end and class_off=false }}
or something
do I need ```
{{false}}{%else%}{{true}}{%endif%}
i honestly have no idea if i am right or not, just wondering.
I remember I had this problem before.
but not sure about the fix
at least I think i did.
I'm going to have to go. Thanks for the help. I'll come back tomorrow. I need to get my friend who helped me originally to check it out again.
yeah, good luck
so the trigger is the time of day and the condition is the calendar
@calm kettle do you have the time set in the calendar? what you posted above was a the whole day
https://hastebin.com/fegigudavu.bash
I'm trying to have my I2C configuration set up in the device_base.yaml and have it set the SDA and SCL pins according to what platform I'm using - this conditional shows "{% if ESP32 == ESP32 %} in ESPHome, but it doesn't return the right pins. Isn't it possible to return the pin depending on the platform?
@calm kettle do you have the time set in the calendar? what you posted above was a the whole day
@bitter atlas Yes it is set for the whole day, the trigger is time.
I think I found a way to make it work. When the calendar event is active/on-going the state of the calendar is on when there are no events the calendar state is off.
{% is state = state('calendar.ouachita_hills_academy') %}
{% set class_off = is_state_attr('calendar.ouachita_hills_academy','description','class off') %}
{{ state= on and class_off }}```
I don't think that is correct but may be someone could help me fix it.
condition is the calendar
trigger is time of day.
@calm kettle petro's code was accurate and gave you more control over fine tuning the template but if you don't care about the calendars event time and just want it to ring True for the entire day and use a separate trigger for time something like this would work
{% is_state('calendar.ouachita_hills_academy', 'on') and is_state_attr('calendar.ouachita_hills_academy','description','class off') %}
awesome, thanks.
Tried to find how to specify state because it didn't like is_state, I couldn't find what to call it.
is_state is a true/false response
how should my template sensor look to show percetage value of battery level which is populated as voltage values in range of 4.2-3.0 ?
@woven cedar you mean this? https://community.home-assistant.io/t/converting-voltage-to-percentage-in-a-value-template/220900
probably, ill look into it
ok but how did he get that {{ ((states('sensor.stacja_pogodowa_bateria')|float-3.0)/**0.0252**)|round(1) }}
0.0252
maths more than likely
well that sucks then π
hi all! i have a litlle syntax problem i'm sure someone have a quick answer to it :
action:
- service: notify.mobile_app_iphone_de_paul
data_template:
message: "mdi:chili-mild {{ states('sensor.vapor_deficit') }}, mdi:thermometer {{ states('sensor.thermohygro3_temperature') }}, mdi:water-percent {{states('sensor.thermohygro3_humidity') }}"
In the notification i don't see the icons, how can i correct this ?
whatever device you are sending that too dosen't know what the heck mdi:some-icon-is
is_state is a true/false response
@bitter atlas
Not sure if I follow you, if it is a true/false response how should I write it?
@calm kettle if you want the actual state of an entity you gotta use states not is_state
Oh ok, so it's state.state, I'm going to try it
@bitter atlas okay thx
TemplateSyntaxError: Encountered unknown tag 'states'
@calm kettle I don't know what you are trying to do, the example I gave you is how it's done
it doesn't except it. I'm trying different things to try to get it to work
where are you putting this code?
what template? in an automation? script? as a template sensor? template binary? where
@calm kettle ```
{{ is_state('calendar.ouachita_hills_academy', 'on') and is_state_attr('calendar.ouachita_hills_academy','description','class off') }}
I see, thanks for the change. the way you wrote it the first time was for where?
for a template sensor or binary
unable to find reference for this issue. Id like this ``` - platform: template
sensors:
spacex_next_rocket:
friendly_name: 'Next Rocket'
value_template: '{{ state_attr("sensor.spacex","rocket")==("rocket_name") }}'
spacex_next_rocket:
friendly_name: 'Next Rocket'
value_template: '{{ states.sensor.spacex.attributes["rocket"]["rocket_name"] }}'``` to evaluate to the same . ie... "Rocket_Name" the first example is my attempt to convert the second example to the newer method that avoids (states.sensor.some_sensor.state) method because it causes error if the states ever returns as unavailable
currently it evaluates like this ``` - platform: template
sensors:
spacex_next_rocket:
friendly_name: 'Next Rocket'
value_template: 'False'
spacex_next_rocket:
friendly_name: 'Next Rocket'
value_template: 'Falcon 9' ```
"rocket_name" is an attribute of the attribute "rocket"
Of the sensor "sensor.spacex"
"rocket" is a list of other attributes
for a template sensor or binary
@bitter atlas
Thanks for helping a noob out
hi, I have a history_stats sensor that is counting the time a sensor is on. The result is a sensor with a number of hours like 8.33 . What's the right way to convert that to a formatted time length? (like '8:20' or '8h 20min')
I guess I can do some calculations to generate that formatted string, but I'm sure there's an easier way
@wheat cargo something similar to this perhaps
@wheat cargo - platform: template sensors: history_stats_friendly: friendly_name: 'Stats History Converted Time ' value_template: '{{ states("sensor.history_stats") | int | timestamp_custom("%H:%M %Z")}}'
@wheat cargo that would basically leave thew other sensor unchanged and create a new sensor called history_stats_friendly that converts the original sensors time to a friendly view. ALSO remove the %Z if you dont need to see the time zone at the end . (ie.... 8:20 EDT. )
https://docs.python.org/3/library/time.html#time.strftime https://docs.python.org/3/library/time.html#time.strftime
More like this perhaps@wheat cargo
now = hass.states.get('sensor.time').last_changed.timestamp measureStartTime = float(hass.states.get('var.ac%s_fan_measure_start_time' %(ac)).state) logger.info('LSX: now=%s start=%s', now, measureStartTime) diff = now - measureStartTime logger.info('LSX: diff=%s', now)
@astral wren: that's python, do you mean I should use a python script?
@astral wren: just in case it's useful for someone else, I did it with a variation of your first idea:
value_template: '{{ states("sensor.history_stats") | float | multiply(3600) | timestamp_custom("%H:%M", false) }}'
Nice I especially like the | float | multiply(3600) |part
using all filters enforces order of operations, nice one
so I don't know what I did, but now in my log book it is constantly turning off my automation.
any ideas?
- at: '12:10:00'
platform: time
condition:
- condition: template
value_template: '{{ is_state(''calendar.ouachita_hills_academy'', ''on'') and
is_state_attr(''calendar.ouachita_hills_academy'', ''description'', ''wed'')
}}'
action:
- data:
entity_id: switch.relay_01
service: switch.turn_on
there's nothing there that would cause your automation to be disabled, but your indentation is wrong
it is?
trigger:, condition:, and action: should be aligned
probably a paste error
I can't show you screenshots can I ?
if it's text, no
.images if you must
Please use imgur or other image sharing web sites, and share the link here.
but if its a picture of text we're gonna slap you
well the automation isn't working either
one offset like that reads to me as a copy-paste error as there should be a key above that that has been ommitted
yeah they are all lined up .
other than that, I don't see anything fishy in that automation
that and the funky double quotes
condition:
- condition: template
value_template: '{{ is_state(''calendar.ouachita_hills_academy'', ''on'') and
is_state_attr(''calendar.ouachita_hills_academy'',''description'', ''wed'')
}}'
this is the part that isn't working, everything before the "and" works but not the description part
if that's actually on a separate line, then that would be a problem
I think?
I'm suspicious of anything that comes out of the UI editor
it's not
then what does
-> States say for calendar.ouachita_hills_academy in the attributes section?
message: Vocational Classes
all_day: true
start_time: 2020-09-16 00:00:00
end_time: 2020-09-17 00:00:00
location:
description:
wed
offset_reached: false
friendly_name: Ouachita-Hills-Academy
weird that "wed" is on the next line
must have a newline in there or something
but may be it hasn't updated yet?
anyway, you can play around with the template in
-> Templates
just went to the calendar and apparently it adds a new line automatically
because I just got rid of it twice and it added it back
you can also something like 'wed' in state_attr("calendar.ouachita_hills_academy","description")