#templates-archived
1 messages ยท Page 110 of 1
I am "trying" to workout is there a way to template a notification that is "temperature was xc overnight" I have a simple automation that covers it was "below xc" , but would be nice to have an actual temp . IS this something a template can do even ?
ahhh maybe ... will need to play .
But im guessing I will need a template to "read" the temp, and a template to make the notification
What am I doing wrong?
My template:
Distance: {{ states.sensor.zwift_online.attributes.latest_activity.distanceInMeters / 1000 | round(2) }} Km
Expected output:
Distance: 30.28 Km
Actual output:
Distance: 30.271900000000002 Km
You're only rounding the 1000 to 2 decimal places
Lol it's all good
https://www.home-assistant.io/integrations/history_stats/ could help
@arctic sorrel as its getting late i will have to play with it some more. but to check ..
entity_id: sensor.temperature_2
state: 'temperature' - is that right to be tracking the temp ?
#obvisuly correct time template i think
start: '{{ now().replace(hour=21, minute=0, second=0) }}'
end: '{{ now().replace(hour=06, minute=30, second=0) }}'
I'd check in #integrations-archived - I don't use it myself, just looks like the only thing that may be relevant here
@dire flare Is the sensor you have in the ground bad? I feel like I would trust that over the weather ๐คฃ
@mighty ledge No it's actually pretty good! It's a miflora that I have polled using esphome
Are templates the only way to make icons change in lovelace? I've got some zwave door sensors that I've templated to open/close icon, but the other zigbee ones don't (obviously). Is this the only way to do it?
as far as I can tell, using the customization, I can only set the new icon, not one for open and one for closed... unless I"m missing how it works.
hmm, interesting, because I had to add this line to my binary sensor for it to showup on my zwave.
icon_template: "{{ 'mdi:door-open' if is_state('sensor.guest_room_door_access_control', '22') else 'mdi:door-closed' }}"
I guess, I could try to take that out and see if the device class is actually the part that makes that happen, i assumed it was that icon_template
Only if you donโt like the ones it chooses with the device_class
ahhh
@fossil hearth clear your cache and reload the page
@mighty ledge tried it did not work : /
I just realized it had syntax errors too
@mighty ledge :0 is that why its not working ๐ haha what should i do ? ๐
I need some help figuring out how to configure a light domain into a cover domain using a template. I have a iblinds motor that is being identified as a light domain. Iโve been working on this template for three days and I just cannot figure it out.
Hello. Talking of time https://www.home-assistant.io/blog/2017/10/15/templating-date-time/ I tried using now().month and it gives " 11 " for november. I am looking to get name itself november than digit. Is there such a function to convert?
Actually i need first 3 letters of current month like nov for november, jul for july, etc
nevermind. Found out solution > https://community.home-assistant.io/t/date-formatting/17461
@hollow rampart, what do you have so far? you should be able to call the light.turn_on service as the open_cover attribute of your cover, light.turn_off as the close_cover... and potentially put smth like this in the template_value: : "{{ 'open' if is_state('light.my_cover', 'on') else 'closed' }}
I have a markdown card in Lovelace showing a template of stuff from a sensor. The sensor is updated every 1800 seconds. What's the best way of showing 'last updated hh:mm:ss' in the card?
You'll want to use strftime to format the existing datetime into your preferred format. https://strftime.org/
If you already have a datetime string rather than a datetime object, use strptime instead. There are a few examples on the templating docs: https://www.home-assistant.io/docs/configuration/templating/
Hmm. I see from your URL that I can for instance do {{ as_local(states.sensor.thesensor.last_changed) }}. That gives me the time it was last changed. But what if I want it to show the last time it checked for change?
I don't think you can. You get information about the state of entities, not all the behind the scenes stuff that got it for you.
So my only option then would be to add another attribute to the sensor with a timestamp?
I maintain the custom component. I was just thinking of grabbing sysdate or the equivalent in python code.
Then yes, feel free to add whatever attributes you want ๐คทโโ๏ธ
I have an entity called "sensor.shelly_shplg_s_0847af_current_consumption". This entity has an attribute called "ip_address". Can I write something in my lovelace card to display this property directly or do I need to define some template sensor that shows this specific attribute first?
I went so far as to write a dot after the sensor name followed by "ip_address", but that failed miserably.
It depends on the card...
I have this entity card used for now, it displays some other properties from the entity but not the IP.
But you mean that I could "pull" this entity information directly into a card somehow? Without the need for creating a template sensor?
@analog plover you can make a template sensor and pull the attribute from it. Otherwise you'd need to use a custom card to pull the attribute. Most built in cards only display the state.
How does last_updated differ from last_changed, mono? When I was adding a last_update attribute to my sensor I suddenly saw the last_updated also existed.
last_updated is the last time something updated the sensor, last_changed is the last time the state changed.
So when I have a scan_interval at 1800 for my sensor, last_updated would change very 30 minutes? ๐
Brilliant. Reverting all changes where I added a new attribute to sensor. ๐
Is this documented? My googling apparently sucks.
yes
Hmm
I might have that wrong
Well, I do have it wrong. Read the fields in the state object, seems like both are a mix of what I described.
Yes. Thanks.
Maybe I need my extra attribute after all ๐
Anyways. Annoying that a google search for 'home assistant last_updated' without quotes doesn't find that site but a bunch of community hits instead
Same with 'home assistant state.last_updated'
Not sure I should be posting in here, or one of the other rooms, so apologies if in the wrong place. I have a lamp with a remote that uses 433Mhz. Luckily I have openmqttgateway already set up with 433Mhz transmitters/receivers for some remote switches so I can see the button presses hitting the MQ. The remote is pretty basic - on/off, change temperature cycles through 3 settings, and brightness up/down buttons. What would be the best approach to create this as a light on Home Assistant. It doesn't have a brightness/temperature setting as you can imagine just the ability to step up/down. I'm thinking a combo of templating and an mqtt light but need a little point in the right direction to work it out.
Good evening everyone. I am trying to convert my received json temperature values reported in fahrenheit to Celsius with the template functionality. Anyone knows how to do this ? I found there is util helper for this but i am not sure if this can be used in templates. This is al new to me. Any hint or help would be greatly appreciated.
I'd make it {{ ((f | float) - 32) * 5/9 }}, just in case the value of f isn't one already
I think that's right lol
or float(f)?
Thatโs fine. Donโt need the extra parens around it, though. Order of operations will make it work
@inner mesa @ivory delta @thorny snow @blazing burrow You don't actually need a template for this guys. All you need to do is set the unit_of_measurement to ยบC and HA will do the rest.
as long as your systemwide units are set to imperial.
Its the only unit in HA that will be converted for you
@hollow rampart posted a code wall, it is moved here --> https://paste.ubuntu.com/p/2TPQnYNPkY/
I need some help figuring out how to configure a light domain into a cover domain using a template. I have a iblinds motor that is being identified as a light domain. Iโve been working on this template for three days and I just cannot figure it out.
@hollow rampart posted a code wall, it is moved here --> https://paste.ubuntu.com/p/DW22XK26tv/
Iโm not getting any errors in configuration checker but I do get an error when I try to tilt Failed to call service ....extra key not allowed @ data
@hollow rampart Rule #6: Spam will not be tolerated, including but not limited to: self-promotion, flooding, text walls (longer than 15 lines) and unapproved bots.
Please take the time now to review all of the rules and references in #rules.
I am trying to modify: {%- if otherPeople > 0 %} personen I want it to display persoon when the value is 1 and I want to display personen when te value is anything above 1. How can I do this?
This has been solved btw thank you @deft timber. I will post solution in the forum.
What's the context, Tuxabyte? Is this part of a bigger template?
{{ "persoon" if otherPeople == 1 else "personen"}} should work
"person{{'en' if otherPeople == 1}}"
not valid since there are 2 'o' if singular ๐ (persoon)
loool, it was in the initial demand :-p
TLDR ๐
Thanks!
Yes, bigger template that outputs the number of detected people from doods (based on Tinkerer's config)
Hello everybody,
need some help with the topic of templates. also in German, because my English is not the best :-)
Thanks and regards
Alex
Hi, I'm looking to create a notify service to an arduino that accepts url queries to signify what color, duration and type of flash method for an led strip. I want to be able to swap out all the numbers with input_numbers in HA. I have a sample url of: [IP_ADDR]/notify?color=1671168&duration=5000&flash=10 What's the best way to construct this url and send the request?
Does anyone know if it is possible to make a custom sensor that will count the number of hours of activity in a room via a motion sensor activation (it doesn't have to be super accurate) that would be resettable. My Idea is the track the amount of traffic in a room and then once it hits a particular threshold it would send out my Xiaomi Robot Vacuum to clean that particular room. (really it would turn on a binary sensor to set the vacuum to clean that room after everyone is gone for a particular amount of time, or possibly when they are all more than a particular distance from home.
hmm a few partial ideas but nothing great
First you'd have to determine what counts as activity. If you're only dealing with something like PIR motion sensors, it's going to be tricky to know for sure how long someone was in that room.
Assuming motion sensors, I'd probably go with dividing the day into time segments and counting how many segments had motion in them. Up to you how granular you want to get... and probably not solved with templates on their own.
Seems like an automation thing... every 5 minutes, check if there was activity in that room in the last 5 minutes, incrementing a counter if there was.
All you need to do is set the unit_of_measurement to ยบC and HA will do the rest.
@mighty ledge My sensor reads in Fahrenheit so i my unit_of_measurement is 'fahrenheit' I expect ? My system is set to metric but values ar
They are special-cased in the code
@inner mesa tried both values for unit_of_measurement but doesn't seem to do any conversion. Only the Icon label changes.
I have a Shelly 2.5 that controls a shutter. I want to set up an automation that allows me to control it with "one" button: meaning, every time the button is pressed, the roller goes in the next sequence step (i.e. Open/Stop/Close/Stop/Open) Would I use templates for this? The shelly already shows up as a cover so i have cover.toggle, as well as open_cover, stop_cover, and close_cover. I guess I would need to retrieve the last step to know which step to perform next in the sequence ?
@mighty ledge Tried all kind of symbols and letters. No luck. This is my code https://pastebin.com/mc65CaJh
This is the only working solution until now :
value_template: '{{ ((states.sensor.Garmon.attributes["tempf"] | float) - 32) * 5/9 }}'
Line 4, tried unit_of_measurement: 'ยฐC' or unit_of_measurement: 'ยฐF'?
@coarse tiger 'ยฐF' works !! I was confused to use the degree symbol together with Fahrenheit. I was thinking it was only needed with Celcius.
I also noticed that unit_of_measurement line can/must be used in both sensor and template section in order to have conversion in both approaches.
You donโt need the template, only the unit_of_measurement
Hello friends, I would like to create a template sensor where the value is only a number. The Value looks like that in the normal sensor:
388.76/453.51GB (85.72%)
the template sensor's value should be 85.72 or 85. doesnt matter which one. Can someone please help me? Thank you.
@mighty ledge My rest call receives multiple values like temperature, windspeed, humidity. They all need their own unit of measurement. Thats confusing to me how to handle without template.
I feel like you didn't read my original message. You don't need to convert anything in a template when you have a temperature, only a temperature. All you need to do is output the value and use unit_of_measurement. Set unit_of_measurement to whatever unit the value is (NOT SENSOR), then the sensor will convert to your units set on the system. Again, this is only for temperature sensors.
So , in your case above, if your system wide units are set to metric then all you need is:
value_template: "{{ state_attr('sensor.Garmon', 'tempf') }}"
unit_of_measurement: ยบF
it will translate it to ยบC for you, without any need for conversion
@mighty ledge Thanks for explaining. I was indeed confused by thinking this was working for other imperial vs metric values I learned a lot.
@rugged lichen : {{ your_sensor.split("(")[1].split(")")[0]}}
@deft timber Thanks, can I check it in the template developer tools somehow? I tried this
{{ state_attr('sensor.radarr_disk_space' , '/') | split("(")[1].split(")")[0]}}
of course its not good ๐ Im sure im missing something.
Yes indeed it is not ๐
at least you tried!
@rugged lichen can you take a screenshot of the entity in devtools -> states page
or copy the results here
/: 388.59/453.51GB (85.68%)
/data: 1460.82/1863.01GB (78.41%)
/config: 388.59/453.51GB (85.68%)
unit_of_measurement: GB
friendly_name: Radarr Disk Space
icon: 'mdi:harddisk'
I would like to use the attribute "/", what is showing the disk space usage of my first drive.
and I would like to see only 85.68 as the value.
{{ states('sensor.radarr_disk_space').split("(")[1].split(")")[0]}}
(if the state of the sensor is the string you copied at the first place)
@deft timber its in the attribute of "/"
ok, try this then {{ state_attr('sensor.radarr_disk_space' , '/').split("(")[1].split(")")[0]}}
{{ state_attr('sensor.radarr_disk_space' , '\/') | split("(")[1].split(")")[0] }}
it depends on how the attribute is presented
@mighty ledge you just copy pasted back what I wrote ๐
/ instead of /
'\/'
Yes
\ escapes the character / to make sure it's passed properly as /
TemplateSyntaxError: expected token 'end of print statement', got '['
@deft timber Your idea was the solution. Thank you very much.
@mighty ledge Thanks for you too for your kindness!
now I just have to create the sensor.
Sorry but I have to ask for that too, thats the first time im doing template sensor and I cannot find the answer to that.
In normal case I would use value.split("(")[1].split(")")[0]
as a value_template in the sensor yaml.
but now I want the split of the state of the attribute.
how should I attach that to my config?
sensor:
- platform: template
sensors:
your_sensor:
value_template: "{{ state_attr('sensor.radarr_disk_space' , '/').split('(')[1].split(')')[0]}}"
Ah I understand, so I can use also the name of the sensor not just "value".
yep
Thanks, I learned a lot, I can start creating my ideas with this information!
Thanks again @deft timber and @mighty ledge I was able to achieve this monitoring card with your help. Today's work was great :)
https://ibb.co/BfFj80f
Glad I could help ๐
@serene matrix posted a code wall, it is moved here --> https://paste.ubuntu.com/p/ns5qsMrKCB/
I just nicely formatted my code ๐
@serene matrix posted a code wall, it is moved here --> https://paste.ubuntu.com/p/XYGwpgFP53/
^ Second part of my message as I hit the character limit
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.
Nice. Over 60 lines of text. I'll pass.
When you "hit the character limit", best to consider whether you're sharing the most useful info
Alright, sounds reasonable. However, it just seems that the "Services" tab under Developer Tools is buggy. Calling the service in an automation with the exact same payload works.
But probably not for too long. Setting legacy_templates: false results in this error when running the automation: expected str for dictionary value @ data['media_content_id'] Reverting the setting plays an audiobook as desired.
Is this worth a GH issue or am I missing the obvious?
I don't know what to think about that. it evaluates properly in the template editor, so I would probably file an issue in Github
Hi, I got a DIY garage controller with ultrasonic sensors angled at the cars, when a car is present, the sensor detects around 1m and shows in HA, if a car isnt present, the sensor says "unknown"
https://imgur.com/a/iogscHu
is it possible, with a template or other, to say the following
Sensor state = < 500mm or Unknown then report state = No
Sensorstate > 500mm then report state = Yes
@heady crow yes it is
I'd suggest a binary_sensor that shows true/false, on/off
For example: {{ states('sensor.your_sensor')|float > 500 }}
ill have a look now, thank you @waxen rune
- platform: template
sensors:
car_present:
friendly_name: "Car Present"
value_template: >-
{{ states('sensor.garage_ultrasonic_sensor_left_2')|float > 500 }}
So i done the above @waxen rune how would i add the true/false to that, or that occurs by default???
So i done the above, State reports OFF even though the sensor reading is showing 1.06m, i noticed it was in metres too, and probably wont show mm, so i changed it to "float > 1" but that also does not work
- platform: template
sensors:
car_present_r:
friendly_name: "Car Present Right Side"
value_template: >-
{{ states('sensor.garage_ultrasonic_sensor_left_1')|float > 1.00 }}
what shows states('sensor.garage_ultrasonic_sensor_left_1') and what shows {{ states('sensor.garage_ultrasonic_sensor_left_1')|float > 1.00 }} in the template testing screen ?
i just restarted with 1.00 instead of just have 1
im getting a new state of "ON" which is great
so my min is now 1m to determine on
How would i now chang e the ON/OFF to a YES or NO
if you wan't yes/no and not on/off, you have to use a sensor and not a binary_sensor
oh ok
and your template should look like {{ "YES" if states('sensor.garage_ultrasonic_sensor_left_1')|float > 1.00 else "NO"}}
Hi, I am having troubles with a "lock" template and controlling an input_boolean from within... more info here: https://community.home-assistant.io/t/lock-template-with-input-boolean/246709
I don't know have already spent a lot of time but I really think this could be a bug?
Whatever i try,I cannot control the lock template (entity) from home assistant lovelace interface, the buttons just don't respond
hi guys i added 3 template sensors , but now log spits out errors cant figure it out ?
Hello
Did you know, if i can template localeโs full weekday name in sensor?
Because, every test i do on model's dev tools, don't work...
I am investigating the following:
@silent vapor posted a code wall, it is moved here --> https://paste.ubuntu.com/p/fR8kbSpTFp/
But this is not allowing the control via lovelace. i think this must be a bug...
@keen sky value_template: "{{ states('sensor.zigbee_bathroom_humidity') - 10 }}"
Thus this also does not work:
@silent vapor posted a code wall, it is moved here --> https://paste.ubuntu.com/p/YHsqR82DtT/
nope, give me error, that invalid key: "OrderedDict([("states('sensor.zigbee_bathroom_humidity') - 10", None)])"
Missed the quote. Sorry. I have updated my message
unavailable
Needs |float
Always test run your templates in /developer-tools/template
If I control the lock via another way then it correclty reports the state (locked/unlocked) but I cannot control it
via lovelace and service
TypeError: must be real number, not str
obviaslu it is read as string ?
value_template: "{{ "$%.1f"|format(states('sensor.zigbee_bathroom_humidity')) - 10 }}"
Yes, RobC is right, all states are strings. Try {{ (states('sensor.zigbee_bathroom_humidity') | float) - 10 }}
@sick haven , {{ now().strftime('%A')}} works for me
Hi.
I am trying to build a garage door template that is not straight forward. Anyone in here who might help?
@sick haven ,
{{ now().strftime('%A')}}works for me
@deft timber hmmm, maybe it's because i have a debian with supervised ha ?
Because this don't work for me ๐ฆ
no, should work for every kind of installation. When you type that in the template testing tool, it doesn't work ?
I have a sensor with this: https://paste.ubuntu.com/p/mynsFS5kVT/
and it don't work
i have the full weekday name in english
ah ok, it is a problem of language...
Lets give it a go :)
I have a garage door that is controlled up or down with a puls switch. I also have sensor that knows the state of the door.
Is it possible to set up a value template for open and close command? So that when sensor reports closed, the close command does not work. And when open the open command does not work. Sort of making seperate open / close commands from just a impuls signal...
ah ok, it is a problem of language...
@deft timber ho yes sorry
my installation is in EN so for me, no problem ๐
๐
obviously ๐
(maybe i don't know the difference between local datetime and the language)
@true acorn , I recommend you take a look at the template cover https://www.home-assistant.io/integrations/cover.template/
no no, I missunderstood
@true acorn That is exactly what I am here for also... I
aha
so it is the syntax of the value template I dont know how to write...
I already has this up and running on a different sw. But since I am in the process of migrating to home assistant I need to get this one to work...
After updating to 0.118 I am getting a template error. Been stuck on this one and can't seem to figure it out, hopefully someone can help (point out I am an idiot ๐
value_template: >-
{{ ((float(states('sensor.routing_multilevel_sensor_air_temperature_5')) + float(states('sensor.routing_multilevel_sensor_air_temperature_3')) + float(states('sensor.routing_multilevel_sensor_air_temperature_2'))) / 3) | round(2) }}
In the logs I get:
2020-11-19 12:44:03 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('TypeError: unsupported operand type(s) for /: 'str' and 'int'') while processing template 'Template("{{ ((float(states('sensor.routing_multilevel_sensor_air_temperature_5')) + float(states('sensor.routing_multilevel_sensor_air_temperature_3')) + float(states('sensor.routing_multilevel_sensor_air_temperature_2'))) / 3) | round(2) }}")' for attribute '_state' in entity 'sensor.living_room_and_cinema_temperature'
From the error I get that "/" is not supported and that it has something to do with str and int but it makes no sense to me.
one more question - value_template: "63.599999999999994" - how can i shrink to xx.xx
one more question - value_template: "63.599999999999994" - how can i shrink to xx.xx
@keen sky Use the| round(2)option like in my example
@grand dust verify that all entities exist.
Also, this is a perfect example for using | float over using float()
float() will not convert the value if it fails to convert. | float will convert the value to the default float, which is zero. So you won't get an error but the template will still work
So during your update, one of those 3 entities no longer exists
@mighty ledge They definitely exist and have values populated.
You're getting an int/string division error
that means your items wrapped in float are not converting
Ok so using | float might solve it?
unsupported operand type(s) for /: 'str' and 'int''
Yes it will solve it but you'll just get 0/3
You should really look into why float is failing on those entities
Thanks @mighty ledge at least I have something to go on
personally, i'd change the template to make it easier to manage for testing.
{% set temps = [
states('sensor.routing_multilevel_sensor_air_temperature_5') | float,
states('sensor.routing_multilevel_sensor_air_temperature_3') | float,
states('sensor.routing_multilevel_sensor_air_temperature_2') | float,
] %}
{{ (temps | sum / temps | count) | round(2) }}
then you can check what's in the list of temps in the template editor by doing
{{ temps }}
so you can see which ones are converting properly
That is so much neater and easier to read!
also, it makes it easier to add temperatures at a later day
Not sure, it worked fine for a long time (since I think 0.44) and only started to give me an error with 0.118
there was a change in how templates output
still doesn't make sense how you were getting a str / int division error if everything was converting properly
maybe there was a change to float()
I got curious, and for me those two works fine and give the same result:
{{ ((states('sensor.kok_temperature') | float + states('sensor.inplastad_temperature') | float + states('sensor.lackagesensor_temperature') | float / 3 )) | round(2) }}
and
{{ ((float(states('sensor.kok_temperature')) + float(states('sensor.inplastad_temperature')) + float(states('sensor.lackagesensor_temperature')) / 3 )) | round(2) }}
so maybe the thing about not converting a missing value?
Another thing, since 0.118, my template
{{ (states('sensor.utomhus_framsida_temperature') | round (1))}}
doesn't show any decimals when the value is exact anymore.
So 1.33 shows as 1.3 as expected, but 1 shows as 1, instead of 1.0as it used to.
Just verified that 0.116.4 show decimals for integers with the same template. I can't find anything in the release notes about that.
Issue or by design?
ints don't have decimals as a rule
bad wording
it's not an integer, a float without decimals
+1
but the issue (?) remains
might want to just use the min_max sensor for these though
I never saw this while in beta. Maybe the temperature just never happende to be exactly 1 degree
otherwise you get weirdness when one of them is unknown because that'll |float to 0
Yep, I might. But should I raise an issue? As far as I can tell it is an undocumented changed behavior. But maybe I'm just a sloppy reader..
{{ "%0.1f" | format(states('sensor.utomhus_framsida_temperatur') | round(1)) }}
TypeError: must be real number, not str
Now the temperature increased to 1.1 so .. problem solved ๐
{{ "%0.1f" | format(states('sensor.utomhus_framsida_temperatur') |ย float | round(1)) }} then
yep, just saw that
I think the main issue is that you were missing float
states('xxx.xxx') is always a string
well.. no. or yes :-)
the main thing is that it has changes since 0.116.4
I don't know how round worked at all on the string prior to the current version, consider yourself lucky
I can absolutely change the template, no problem. but it works differently than before
I'll do a CTRL+H and just update the template sensors. Still confused why it happened though.
there should be nothing to be confused about
you literally got lucky that the template worked before
it just so happens that it now errors because of changes
that's fine. I'm just looking for the reason so it can be documented
If it happens to me, it will probably happen to others
So, what's the value of states('sensor.utomhus_framsida_temperatur')?
if it's a whole number, it will truncate the .x because it's not a number its a string
whole number meaning '1.0'
that one changes so often, so let's take this instad: {{ state_attr('weather.home', 'humidity') | round (1) }}
in 0.116.4, it shows 68.0
'1.0' | round(1) returns 1
'1.1' | round(1) returns 1.1
all because it's a string
but the state is 68
ok, then your result will be 68
now, yes. in 0.116.4, no
I don't argue with that. I know you are king of templates. But something has changed. that's fine. I'd like to document what
but it's no biggie.
Ok, so it seems like this is a result of the typing changes
it is a bug
Also, they added conversion of for users inside the round function. float is not needed
0.116.4: https://imgur.com/a/6VGTDPi
0.118.0: https://imgur.com/a/Fwbw4XD
ah, ok.
I'll leave it here. I just noticed the difference. If an issue should be raised, I'd appreciate if one of you who actually know what you're talking about do it ๐
hello, when I try this in dev tools : "{{ "%.1f" |format(states('sensor.zigbee_bathroom_humidity')|float - 10 ) }}" it work fine. but when i put in my .yaml file give me error: found character '%' that cannot start any token. How to fix that ?
@charred dagger even formatting fails {{ "%0.1f" | format('1.0' | round(1)) }} does not work. It's a bug, put a PR above.
you're chopping your template with your quotes
@keen sky : "{{ '%.1f' |format(states('sensor.zigbee_bathroom_humidity')|float - 10 ) }}"
if you put double quotes around your template, use single quotes in it
Hi is there anyone able to help met with a "template" problem? I have trief with a lock template... had some result but not stable. Now switched to cover template (nicer for my gate) bt I seem to have the same unreliability problems...
The problem I am trying to solve is very simple. i have a gate that opens and closes with a pulse (is now a switch entity in home assistant)
pulse ~1-2 sec: open, pulse ~1-2 sec: close
and a door sensor (on/off) connected to the gate (to see the state)...
that thread seems to indicate that you think you solved it
@exotic arch Don't ask to ask, just ask your question. Then people can answer when they're around.
When you do ask a question, try to provide as much background detail as possible. Ask yourself these questions first so that others don't have to:
- What version of the Home Assistant are you running? (remember, last isn't a version)
- What exactly are you trying to do that won't work?
- Is the problem uniform or erratic?
- What's the exact error message?
- When did it arise?
- What exactly don't you "get"?
- Can you share sample code, ideally with line errors where the error occurs?
Hi all, I made a value template to change a switch value from on/off to open/closed. Problem is that I now see a ' after the value in lovelace...open' or close'. How do I remove this - ' -
Hello, Can i access an attribute of a sensor (temperature of climate integration) without having to use a template sensor some how?
@barren rose posted a code wall, it is moved here --> https://paste.ubuntu.com/p/XPbx8GVg5F/
hey, I'm trying to do this script to show on the frontend as one "sensor" with the time remaining
but its not working, is it even possible this way?
https://paste.ubuntu.com/p/RQ5jcNNg6W/
@exotic arch, could you share your template?
@brisk temple cool thanks
@exotic arch posted a code wall, it is moved here --> https://paste.ubuntu.com/p/sJD4fTtTGF/
Well it is because you have an extra quote in your template ๐
@deft timber thanks for helping out ๐
@deft timber Shi* you are right! thx buddy...drove me crazy!!
@barren rose i'm not sure what your trying to do
didnโt really understand neither ๐ but I think you have an indentation problem. data_template should be aligned with service
And the fact that you are building a time like this : 00:00:00:00 is strange to me, the :00 at the end shouldnโt be there.
Hello everyone!
I am trying to get the current energy meter tariff.
I tried with the following but I'm not sure it's working as intended:
{{ย is_state('utility_meter.generale_consumo_giornaliero', 'F1') }}
There's some other attribute I should use instead to get the current tariff?
The tariff is an attribute of a utility_meter, right? Not the state itself.
@ivory delta I think the same, but I can't find the correct attribute
What do you see when you search for that entity at
> States?
It will show you the state and all available attributes.
I see:
state: F1
state attributes:
- F1
- F2
friendly_name: generale_consumo_giornaliero
icon: 'mdi:clock-outline'```
Ok, so the state is what you want to check ๐ What does the template you shared show in
> Templates?
It outputs True
But you want the tariff name?
{{ state('utility_meter.generale_consumo_giornaliero') }}
No, I wanted the true/false state... Give me a second and I'll explain (I'm italian and I'm a bit slow writing english)
The template works... So the problem is that I don't know how to set the tariff manually...!
How can I call the change tariff service manually?
(I just started to play around with the automations, please excuse me if my questions are way too obvious...!)
You'd call one of the utility_meter services: https://www.home-assistant.io/integrations/utility_meter/#service-utility_meterselect_tariff
utility_meter.select_tariff sounds like what you're after. You'd call it from a script/automation or even from a #frontend-archived button action.
Great! I'll use the frontend button (I have some automations in place that call select_tariff but I'm debugging them, that's why I need to change the tariff manually)
Thank you very much!!!
@ivory delta I used a button to change tariff manually, and I've also found the issue with my automations (the name of the tariff was uppercase but in the automation was written lowercase......). You really helped me a lot, your suggestions really helped me solve the issue a lot quicker... And since it's midnight here I appreciate even more your help!!!
No problem, glad to help.
umm, about to update to 0.118... any type of templates I should be particularly concerned with not carrying over correctly?
plez advise, why trying to reverse a switch in configuration.yaml doesnt seem to have effect. sonoff controls radiator valve. it's normally open so "on" relay means "off" radiator so I need to reverse it for generic thermostat.
https://paste.ubuntu.com/p/Q3c3NY3nC5/
shouldnt that do the trick? or this template gets ignored by
climate:
- platform: generic_thermostat
that comes later?
Hey all, I'm trying to write an automation that turns off my christmas lights every morning at 9am but I'd like to put a condition to NOT turn them off Christmas day. Mono suggested in automations channel that it could be a condition using a template saying something like 'month is 12 and date is not 25' ? Need some help with that since I've never used templates if someone can help. Here's my current automation https://paste.ubuntu.com/p/dqbDBvygtf/
It'd be something like this: {{ now().month == 12 and now().day !=25 }}
You can test it in
> Templates and tweak the numbers to see if it works.
oh nice, thanks!
That will also restrict it to December
is this how I would add it to the yaml (I'm sure i'm probably wrong)? I'm having a hard time understanding the syntax after reading through the docs
- condition: and
conditions:- condition: date
type: template
data: {{ now().month == 12 and now().day !=25 }}
- condition: date
nevermind, i think i'm doing it right through the gui
@inner mesa when you say it will restrict it to December, do you mean that the automation will still run in November? and it will ONLY not run on 12/25? Hopefully thats what you mean because that's the behavior I'm hoping for
Does anyone have an example of how to use code_template to define more than one code for the manual alarm control panel?
I don't understand what the formatting should look like from the documentation.
so, been trying different things because i'd like this to run in Nov,Dec, and Jan but NOT run on Dec 25. Tried this with the template editor but it's not giving me the right value, says true for everything. {{ now().month == 11 or now().month == 12 or now().month == 1 and now().day
!=19 }} <-- I was hoping it'd say false since today IS the 19th
not (month == 12 and day == 25)
oh thanks, much simpler to getting this to work ๐ {{ ( now().month == 11 or now().month == 12 or now().month == 1 ) and now().day
!=25 }}
So I can't figure out why my sensor icon isn't changing. It stays as the eye, everything else works.
sensor:
- platform: template
sensors:
wind_direction:
friendly_name: 'Wind direction'
icon_template: >
{{'mdi-compass'}}
value_template: >
//removed for brevity//
hello everyone!
I've got a problem with a template sensor. Its template is built taking into consideration the value of other two sensors. When I paste the template into developer tools, it works out nicely. However, when I check the state of given sensor in Developer tools, it shows "unknown". Any ideas?
it's not an identation problem or anything of the sort, the sensor has been working great until yesterday, and I didn't change anything
@sleek tinsel You probably copied it from https://materialdesignicons.com/? Replace the dash, try {{'mdi:compass'}} .
@thorny snow Mind to share? Probably easier to help then. And what happened yesterday? Upgraded?
yep gimme a second
what happens is, this template, I use the exact same one for 4 or 5 sensors
it's been working great for the other 4 sensors.. now with this one,it's doing this strange behaviour... A couple of days ago it behaved the same way. Worked nicely under developer toolstemplate, but shower "Unknown" states.. I managed to get it working by moving the code a few lines below in configuration.yaml.. I copied it and moved it and it began to work.. now it's back to doing that
should I use pastebin?
pastein ain't working, so..
@hasty topaz posted a code wall, it is moved here --> https://paste.ubuntu.com/p/7DQDm7ys3b/
see, the same just happened, I went to configuration.yaml, moved it a few lines down, and it's working again...
all involved sensor are being updated every 5 minutes..
@desert crane I donโt see any reason why it should not work
any error in log?
does it work when sensor.nadal_playing actually is playing?
I tried the code but replaced the sensor. it works when the first if is true, otherwise I get TypeError: unsupported operand type(s) for -: 'NoneType' and 'float' in dev tools
I'll check for error, I just restart and the log cleared out..
but isn't it rare that it works in developer tools?
and ends up broken out from there?
did you check my question above? that would indicate there is an error in the else part.
what happens if you just cut out the first if? here it doesn't evaluate in dev tool then
Well, I would start there. I hope you find it!
yup, I believe I'll do the sensor in some other way...
I'll check for errors
thanks
I cut the first if and it's still working
I should work, but now you got me curious again. Now it works, but it stops working .. when?
not sure when.. I just made it yesterday..
After Y time or Y state changes or ..?
what I know is that if I delete it, restart HA, repaste it, restart HA, works again
ok
first time it stopped
I didn't even delete, I just copied it from YAML and moved it like 50 lines below, and it suddenly worked :S
and now when it works, does it work no matter the sensor.nadal_playing and sensor.nadal_utc states?
since those are the only variables (except for time)
I made it yesterday and as of now I can confirm it has worked with two different values of each of those sensors
btw, I'm updating all sensors involved every 5 minutes with homeassistant.update_entity
you could manually change the states of sensor.nadal_playing in dev tools to begin with
just to provoke
Dev Tools > States
I see the blue button, yep
cklick the entity sensor.nadal_playing , change the state to (whatever) in the field State on top
Click Set State
it won't change the actual state (nothing will start or stop playing), but it will change the state = test the template
yep, I moved it back and forward among the two posible states and it's working..
just ruling out the unexpected
yep, works.. triggers the automation
I understand, it feels so silly, one has to try silly things
If we can't provoke it to produce an error, I guess you need to keep an eye on it and check the logs as soon as it appears again
that I will do... if it gets too silly, I'll just built the sensor in some other way I believe.. what's weird is that that very same template, I use it with other 4 sensors and they have showed no problems at all :S
thanks for your time!
just one question, does this need to be float ?
as_timestamp(now())|float)
when I provoked it, I got a operand type(s) for -: 'NoneType' and 'float' which would indicate a relation. A stretch maybe, but since we don't find anything else..
I'll start from there then, I believe it needn't be a float
or the other way around, if that one does - maybe states('sensor.nadal_utc') also should?
again, swimming in deep water now ๐
good luck!
hehe
I appreciate your time
I'll start from there..
wish me luck I'm not back here with this issue ๐
have a good day
same to you. and please report back if you solve it. always good to know what it was
I have camera screenshots saved with date & time config/www/(voordeur_{{ now().strftime("%Y%m%d-%H%M") }}.jpg). How can I make home assistant display the latest local image file in lovelace ?
I think the easiest is to make two copies of the screenshot, one with the current name, and one with a static that always in overwritten. then you won't even need a template in lovelace.
Thank you, haven't thought of that
To make a new reversed dummy switch, i should not use the same entity name down below? How is new entity defined, can i just write whatever into there and due to being defined there, an entity is made?
https://paste.ubuntu.com/p/Q3c3NY3nC5/
an entity switch_state_revert will be create in your case, that's the name you gave it
switch.switch_state_revert
oh thats the entity name.. doh, right. Thanks
thats where i was failing at ๐ @ivory delta
my noob thinking was, that my original switch gets reversed, after sleeping i thought about defining new entity, and i was already doing it as i now found out
thomasloven showed me a nice Lovelace card where you would toggle different rooms to vacuum and then hit 'vacuum'. He's using this python script: https://github.com/thomasloven/new-hass-config/blob/master/python_scripts/clean_rooms.py but suggested to do it with a normal template in a built-in script instead. How do I do that? ๐
hi guys anyone have an alternative to speedtest.net integration ? mine is giving inaccurate results, nowhere near my real speeds i have 300mbit/300mbit sensor.speedtest only outputting 80/90 (yes its on an 1gbit network card)
What device are you running it on?
Corelec machine Arm based
which has a 1gbit nic
when i run speedtest in browser it gives normal results
maybe to do with running HA as a docker container ?
I don't know much about Docker but I don't think it would limit the bandwidth like that.
You used the browser on the same machine?
nope my home pc
So they're not comparable...
your right
You need to consider all of the infrastructure between HA and the internet. Even bad wiring from that device means it won't get 1Gbps
My HA host has crappy wiring but I don't care about it getting maximum bandwidth. It just means that running Speedtest from HA gives inaccurate results ๐คทโโ๏ธ
Also... we're in #templates-archived ๐ If you want to continue this, take it to #general-archived
@sleek tinsel You probably copied it from https://materialdesignicons.com/? Replace the dash, try
{{'mdi:compass'}}.
@waxen rune
Yup that's what it was, thanks!
Btw, is there a faster site that indexes MDI icons?
@waxen rune hey, I realized.. that sensor I showed you before depends on another 2 sensors. Those two sensors are scrape sensors, might that have anything to do with the issue? however, when I check the state of those scrape sensors in developer tools, they both show a state
as long as those always have the predicted states you should be fine. might need some error handling if they scrape up something unexpected though
is it possible to template a entity picture on something other then a sensor?
changing a persons entity picture based on if there home or away, or change a entity picture of a blind when it's open or closed.
found a way using custom_ui
Before v0.118 I was able to write json STRINGS to a file for later retrieval. Now these same templates look like type 'dict' which cannot be written directly. So my question is, how do I convert a 'dict' to a string so it can be written to a notify file, and read back in as a sensor?
What does your template look like now?
{"Nov":[{"d":15,"$":2.62},{"d":16,"$":2.56},{"d":17,"$":2.51},{"d":18,"$":2.24},{"d":19,"$":2.25}]}
I've been writing lines like that to a file and was able to read them back in without issue. I can still read them back in but I can no longer write them using notify.file
The template, not the output
the template i pasted in above was the last line I was able to successfully write to the notify file. ...
sorry ... yes its a string ... that string comes from this template: "{{ state_attr('sensor.household_energy_cost_tracker','bill_cycle_json') }}"
and that attribute is a JSON dict
Try just adding | to_json to the end to force it into JSON (which is a string representation of an object, rather than the object itself):
{{ state_attr('sensor.household_energy_cost_tracker','bill_cycle_json') | to_json }}
When you load it, you may need to do the opposite (| from_json)
are you sure I can write that to a notify file? ?
I'll give it a shot and let you know. it seems like notify file will only write strings... unless the 'to_json' filter converts it to a string
That's what I just said. | to_json makes it a string.
Dicts aren't JSON. Dicts are objects in memory. JSON is a string representation.
If you want to make something portable (HTTP/logs/text/etc), you use JSON.
I see. got it. thanks so much for your help ... I'll give it a shot
@blissful mirage I'd wager that it's a bug due to the template changes
yep...
I would assume there is no work around and you should report it
Isn't the workaround what I suggested?
It won't implicitly return a string now, gotta force it.
I doubt it will work because the parsing happens after the fact
but it's worth a shot
Well TGG's all set to test it ๐
I'll give it a shot, but i did try doing just that before coming here in the developer tools/templates and it just converted it back
I'll let you guys know regardless... thanks for the help. Never used Discord before
If it converts back when you do it to your log file, definitely report it.
will do... now stupid question. where do I report 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
I think this'll be core since that's where it's evaluating the template.
thanks
no joy. same error:
2020-11-20 17:32:43 ERROR (MainThread) [homeassistant.components.automation.home_assistant_shutdown] Home Assistant Shutdown: Error executing script. Invalid data for call_service at pos 2: template value should be a string for dictionary value @ data['message']
Ah, definitely a bug then ๐ฆ
ok. thanks again. you guys have been great
No problem. ๐
Issue #43451 submitted (https://github.com/home-assistant/core/issues/43451)
is there an explode(",") or split(",") function in jinja? can't find one...
i know there's a join(), so why isn't there an opposite?
The air quaility is {{ states('sensor.waqi_friendly_detail').split(' ')[0].upper() }}
yes indeed sorry, | split() does not, @blissful mirage was right ๐
thanks
also, i'm trying to set my template sensor unit of measurement to a template value
but... it doesn't like it
Hey guys, does anyone have ANY example of using code_template for the Manual Alarm Panel? I would like to have more than just one code to disarm my Konnected.io system, but I'm just not understanding what the formatting should look like.
- platform: template
sensors:
baby_sleep:
value_template: |
{{ relative_time(states.input_boolean.baby_bedtime.last_changed).split()|first|int }}
friendly_name: 'Baby Sleep'
unit_of_measurement: |
{{ relative_time(states.input_boolean.baby_bedtime.last_changed).split()|last }} # NOT WORKING
@inner mesa Oh ok. So no way to give each person in my house a different code really. At least from that example, you can only assign a different code for each possible alarm status.
i'm basically trying to have the unit be whatever the relative_time function decides - it could be "seconds" or "minutes" or "hours"
The backend doesnโt know whoโs logged in, so I donโt think thatโs possible
Thanks! I can live with one code. Much better than the old piece of junk alarm system that was in this place when I bought it.
@torn meteor, not sure you can use a template for the unit_of_measurement
dangit. can we make that dynamic? would you think that's a good idea?
(to open a PR)
from my point of view, everything should be usable with a template ๐
eh stuff like that is harder
can someone explain to me how to use template inside an array? for instance:
parameters:
- play
- {% if is_state("input_select.slaap_scene_speaker", "Woonkamer") %} media_player.woonkamer_lms_original
{% elif is_state("input_select.slaap_scene_speaker", "Kantoor") %} media_player.kantoor_lms
{% elif is_state("input_select.slaap_scene_speaker", "Slaapkamer") %} media_player.slaapkamer_lms
{% elif is_state("input_select.slaap_scene_speaker", "Woonkamer & Slaapkamer") %} media_player.woonkamer_slaapkamer_lms
{% endif %}
I need that template block to be the 2nd option of the array
but I can't figure out how to make that work
copying/pasting breaks the script
the template by itself does work (for instance when using only parameter: > and then template on the line below it
Pretty sure you can't do that. You need your template to output the desired array, not just part of one.
Hmm so itโs impossible to template a service call where one of the elements is a list?
The parameter has 2 variables in the list: 1 is play and the other is entity_id
So I would need a template that outputs play and entity_id?
Sorry, itโs not entity_id but a spotify/tidal link (doesnโt matter in this context though)
if you're on 118 you could try:
parameters: >-
{%- set map = {
"Woonkamer": "media_player.woonkamer_lms_original",
"Kantoor": "media_player.kantoor_lms",
"Slaapkamer": "media_player.slaapkamer_lms",
"Woonkamer & Slaapkamer": "media_player.woonkamer_slaapkamer_lms"
} -%}
{{ ["play", map[states("input_select.slaap_scene_speaker")]] }}```
thomasloven showed me a nice Lovelace card where you would toggle different rooms to vacuum and then hit 'vacuum'. He's using this python script: https://github.com/thomasloven/new-hass-config/blob/master/python_scripts/clean_rooms.py but suggested to do it with a normal template in a built-in script instead. How do I do that? ๐
hi, could someone help me with read value from mqtt_sensor? I have value like this: 21.88;65185;ok ยฐC. How I can read only "21,88" ?
{% set data = '21.88;65185;ok ยฐC' %}
{{ data.split(';')[0] }}
@cold hazel try that second line
hello guys. how can i use sun elevation angle as a value for light brightness. Here is what i have and trying to figure out how to set value with sun elevation change. https://paste.ubuntu.com/p/rQHSmCptZS/
you could use a template as part of the light.turn_on service described here: https://www.home-assistant.io/integrations/light/, and then trigger variables as described here: https://www.home-assistant.io/docs/automation/templating/
the second part is where im stuck. can i get an attribute value (sensor.elevation) and pass it on to brightness_pct (im sure after running it through a numeric filter to get whole numbers etc).
yes, you can reference the elevation in a template, which you can pass to the light.turn_on service in the data: section
you don't even need to use a trigger variable for that, just the current elevation attribute
as such
action:
- service: light.turn_on
data:
brightness_pct: 10
entity_id: light.blue_spectrum_brightness
mode: single
how to reference the elevation attrubute to substitute the hard value i.e. "10" in above paste
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
Don't forget you can edit your post rather than repeatedly posting the same thing.
For over 15 lines you must use a code share site such as https://paste.ubuntu.com/ or https://www.hastebin.com/.
you use a template
When working with templates, don't forget:
- You can test them in Developer tools -> Templates
- HA before 0.115: rule 1 and rule 2 (https://www.home-assistant.io/docs/automation/templating/#important-template-rules)
you'll need to decide how to convert the sun's elevation to a brightness_pct based on whatever formula you wish
but this will return the sun's current elevation: {{ state_attr('sun.sun', 'elevation')|float }}
this is certainly wrong, but you could use it directly like this:
i beleive if can divide this by 2.55 as such {{ state_attr('sun.sun', 'elevation')/2.55 | float }}
data:
brightness_pct: "{{ 10 if state_attr('sun.sun', 'elevation')|float < 5.0 else 20 }}"
{{ state_attr('sun.sun', 'elevation') | float / 2.55 }}
but, yes
you can test the formula in
-> Templates
so once i save this automation and i went ahead removed the trigger part. it sets brightness_pct to null.
brightness_pct: null
did you test it?
I believe you need to edit the YAML directly to use templates in the UI
i see
this maybe not allowed in UI
that makes sense
i know its formatted correctly. it still marking it with error.
missed comma between flow collection entries at line 460, column 59:
... tate_attr('sun.sun', 'elevation') | float / 2.55}}
@mellow knot posted a code wall, it is moved here --> https://paste.ubuntu.com/p/FxVsRWvfJB/
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
Don't forget you can edit your post rather than repeatedly posting the same thing.
For over 15 lines you must use a code share site such as https://paste.ubuntu.com/ or https://www.hastebin.com/.
you missed the quotes
I also recommend indenting entity_id: by 2 spaces, but it may not be necessary there
RobC thank you so much for the help so far. i cant believe after all this its still not working. i even added a trigger just to see if elevation change would do anything but still at the same place. here is my automation so far. https://paste.ubuntu.com/p/hvYPDj6RZn/
do you want to use the state of sensor.elevation in brightness_pct?
its really the same as sun.sun elevation but i wanted to try it any way.
what isn't working?
its not setting my light brightness. so basically elevation (sensor.elevation and sun.sun elevation) are 35%
and what does the next_change attribute represent for sensor.elevation?
i figured if multiply by 4 i get around 56 and thats what i was hoping the light brightness would set to
where does that sensor come from?
sensor.elevation is coming from sun2 component
Multiplying negative numbers by 4 still ends up with a negative number, btw ๐
You don't want to use elevation directly.
You said you want it to emulate the real brightness, right?
No light after dark? Brightest at noon?
yes
Then you almost have the right idea. You just need to ignore negative values. And it'll still be a pretty rudimentary solution compared to just using flux.
for some reason flux didnt work for me and then i attempted to use circadian lighting which implements around the same way. both no go.
i am able to change brightness for the same lights manually. np
Try something like this...
{{ ([states('sensor.elevation'), 0]|max) * 4 }}
should i go ahead remove trigger then or keep it the same.
Should never go negative, since you're always picking the larger value of the two in the list. Tweak your scaling factor to suit your needs.
You still need a trigger ๐
current sensor.elevation next_change is ok for this scenario?
I'd skip the attribute though. If all you define is the entity_id, it'll trigger whenever any property of that entity changes.
State and attributes.
Slight adjustment since it complains if you don't cast to a float:
{{ ([states('sensor.elevation')|float, 0]|max) * 4 }}
saved and testing this now
I just tested with these. First one first -26ยบ and second gives 0:
{{ state_attr('sun.sun', 'elevation') }}
{{ ([state_attr('sun.sun', 'elevation')|float, 0]|max) * 4 }}```
Stupid bot.
Can anyone please take a look at my switch yaml to use the icon_template? https://paste.ubuntu.com/p/RC3M6R3g2x/
Yep, looked at it. You're welcome.
The error tells that "Invalid config for [switch.mqtt]: [icon_template] is an invalid option for [switch.mqtt]. Check: switch.mqtt->icon_template. (See ?, line ?)."
Well it's not wrong. There's no setting for icon_template for that integration.
@ivory delta Thanks but how can I add such a setting to the integration?
You don't unless you're a developer. What are you trying to do?
still no go ๐ฆ i used developer tools -> states to set sensor.elevation to 30 and my brightness is still at 1%
I like to have icons changed interactively in lovelace.
Then you probably need to look at whether you can have dynamic icons in whatever card you're using. Try over in #frontend-archived
Are you using my templates or have you adjusted them to use sensor.elevation?
i havent tried with sun.sun elevation using your template. let me give that a shot
Try it in the Dev Tools first and tell us what they give.
One step at a time... get the templates right, then worry about your automation.
there are really only two things that you need to work, and you can check them independently - that the trigger triggers on changes and that your formula in the template returns the value you expect
Exactly. Trying to get the latter right first since it's easier to 'see'.
Once the templates work as expected, it's easy enough to test the trigger.
at 33 degree using {{ ([state_attr('sun.sun', 'elevation')|float, 0]|max) * 4 }} gives 130.72
Great. Positive values. Tweak the factor how you'd like it.
Then use that template in your automation ๐
You already know you're going to be working with values from 0-90.
Hi all! Pretty new to HA and trying to get better at coding. I have scrubbed through quite a bit of forums but I haven't found anything quite like I am after. I am trying to setup an automation for when everyone is away from home and to set the thermostat temp accordingly to the mode that it is in. Am I on the right track and can I use helpers in place of the values?
Do you mean the section from line 23?
That won't work. It'll return the strings 'input_text.heat_away' or 'input_text.cool_away'. You want the values from those inputs, right?
Nah, you're okay here. Your question is about the template ๐
Yes
data: "{{ states('input_text.heat_away')if is_state('climate.lyric_85db34', 'heat') else states('input_test.cool_away') }}"```
Meh. That looks messy on one line ๐
Multi-line:
data: >
{% if is_state('climate.lyric_85db34', 'heat') %}
{{ states('input_text.heat_away') }}
{% else %}
{{ states('input_test.cool_away') }}
{% endif %}```
Both do the same thing. You need to use a template to extract the value before it's returned ๐
Got it. I need to pull the states for that value.
I have the input as text with a numerical number. That won't be an issue right?
It should be okay. Whichever integration you're sending that data to should convert the data type if it needs to.
Ok. It's a honeywell thermo using homekit
Should be fine ๐ Test it and see how it goes.
Thank you!!! I will go work on it right now and test.
Error that I am getting
Invalid config for [automation]: expected dict for dictionary value @ data['action'][1]['data']. Got None. (See /config/configuration.yaml, line 9).
Oh... you'll probably need to assign the value to a key within data, not to data itself.
Probably the temperature setpoint.
Yeah, data might need a few other things. Check the climate docs for that and if you're still stuck, head over to #integrations-archived
That's what I was just looking at. Now visual studios isn't complaining ๐ค
Works as expected!
Thank you for your help! Really appreciate it!
No problem
hi, what Im doing wrong with mqtt sensor value_template:
value_template: "{% if is_state('sensor.kociol_zawor_co_cwu', '0') %} CO {% elif is_state('sensor.kociol_zawor_co_cwu', '100') %} CWU {% endif %}"
state from mqtt is 0 or 100
for 0 I would have state = CO, and for 100 state=CWU
value_template: "{% if ('sensor.kociol_zawor_co_cwu', '100') %} CO {% elif is_state('sensor.kociol_zawor_co_cwu', '100') %} CWU {% endif %}"
this one working ๐
I'm a bit confused again... I have a fan I can control with IR... so I'm using a broadlink thingie to send commands to it, which work just fine using some scripts like the documentation suggests... now I would like this fan to be a "fan" integration, so I create a "template fan". But it needs a "value template" and a "speed template" for knowing the state of the fan. I do not have any state of the fan other than a reasonable guess based on what signals I've sent it... how should I approach this? Can I make a "dummy" state for the fan... a best guess and use that to feed the template?
oh, never mind, I got it working now ๐
hello :)
I am encoutering something unexpecte with the change of template type.
I am trying to output the string 'None' but i always get an error string value is None for dictionary value @ data['option']
both with "{{ 'None' |string }}" and "{{ 'None' }}"
any idea why the template seam to return a None object rather than the string i ask ?
Is there a way to get the area of a device?
I don't think you can via templates. You have to go poking around in the UI or in the files the info is stored in.
Areas aren't incredibly useful yet. Groups make more sense.
Thanks ๐
@north acorn posted a code wall, it is moved here --> https://paste.ubuntu.com/p/yTnHrgvVYX/
sorry, I posted the code like that.
can someone help me with that question?
it doesn't look to bad. any idea what doesn't work ?
when i do it i have an extra tab in front of the template
{%- if is_state("input_boolean.salon_ambiance", "on") -%}```
@ivory delta and @inner mesa thank you so much for helping me with solar elevation -> light brightness yesterday. Had to run out in a rush so never had a chance to thank you guys for all the help. Cheers.
was this addressed to me?
so, what I do know is that has to do wih the line itself. I tried by removing everyting and only use ["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"]
which does work
but when having that inside {% if is_state("input_select.wekker_alisina_spotify", "Global Top 50") %} ["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"]
then it doesn't woerk
no errors either
I made sure the input_select is correctly
selected
did you try it in the template page in developement tool ?
that says: TemplateSyntaxError: Encountered unknown tag 'elif'.
but I have that template setup as well, with different parameters which does work: {% if is_state("input_select.wekker_alisina_speaker_lms", "Woonkamer") %} media_player.woonkamer_lms_original
this does work
So this is the whole code:
the entity_id part does work correctly, but the parameters part doesn't
if I remove the elif template and only leave the part behind it, it does work
just to make sure, try {% elif is_state("input_select.wekker_alisina_spotify", "Discover Weekly") %} {{ ["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"] }}
doesn't work either
using only ["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"] does work
but the elif is_state part does work with other parts of the script, that's whats so confusiung
what about {%- elif is_state("input_select.wekker_alisina_spotify", "Discover Weekly") %} ["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"]
with the -
it generate it like parameters: >["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"], no new line
yes correct, it's either that or:
`parameters:
- play
- spotify:playlist:37i9dQZEVXbMDoHDwVN2tF`
but I don't think I can template it like that
sure you can :)
let me find a working exemple
my initial thought was:
`parameters:
- play
- elif_template here-spotify:playlist:37i9dQZEVXbMDoHDwVN2tF`
But someone here told me to put them together instead
but I couldn't figure that out, so tried it with that other method
i don't know i'm not very good, i just know i have done it somewhere
for exemple i have done that before you could make list from template
brightness: '255'
effect: 'fade_blink'
white_value: '0'
rgb_color:
- "{{ {'night': [0, 126, 255], 'total': [255, 0, 0], 'perimetric': [ 255, 63, 0 ]}.get(trigger.event.data.level)[0] }}"
- "{{ {'night': [0, 126, 255], 'total': [255, 0, 0], 'perimetric': [ 255, 63, 0 ]}.get(trigger.event.data.level)[1] }}"
- "{{ {'night': [0, 126, 255], 'total': [255, 0, 0], 'perimetric': [ 255, 63, 0 ]}.get(trigger.event.data.level)[2] }}"
how about something like that @north acorn https://paste.ubuntu.com/p/W9ThhWSy9N/
I think I have it working
๐
You saw nothing
haha
:p
thanks for all your help!
I combined your code with what I had
and that did the trick somehow
having it as an array
happy that it work, surely not the cleanest but at some point you have to have something ;)
Because my own question is a bit burried now, i'll copy past it.
I am encoutering something unexpecte with the change of template type.
I am trying to output the string 'None' but i always get an error string value is None for dictionary value @ data['option']
both with "{{ 'None' |string }}" and "{{ 'None' }}"
any idea why the template seam to return a None object rather than the string i ask ?
Getting python errors from _template_changed_listener calling event.data.get("entity_id"), AttributeError: 'NoneType' object has no attribute 'data'
perhaps related to me using states.group.front_motion.last_changed ? Is there a more correct way to access the last_changed value?
Template works fine in the dev tools UI and the same template in a wait_template action in a automation is properly waiting while it evaluates to false but once it goes to true, it's throwing that error.
isn't last_changed something you can get with state_attr ?
doesn't appear so
doesn't work in the template editor UI
I'm not sure this is related to that use of that property actually.
trouble is, the Event parameter to that function is null which suggests something further up the stack is confused.
what do you have in trigger ?
{{ states('sensor.time') and states('group.foyer_motion') == 'off' and (as_timestamp(now()) - as_timestamp(states.group.foyer_motion.last_changed)) > 60 }}
This is an action triggered by the motion sensor group. An earlier action turns on lights. I've removed the later actions for now.
if this is your trigger, there is no entity id in your event
because it's not a state change
it's a template change
Not following. The error is here https://github.com/home-assistant/core/blob/0b5851e4039c4f5dcc5f66101b319521b658d18a/homeassistant/helpers/event.py#L716
That method assumes a non-none event argument.
the calls to event.data are throwing an exception
{{ states.group.front_motion.attributes.last_changed }}
Last changed isn't something you can get directly from the state object.
it works in the template editor UI
can't you just use a
- platform: state
entity_id: group.foyer_motion
to: off
for: "00:01:00"
```
right now your trigger is a template.
So the event object is empty
when you later call event.data.get("entity_id") you get an error because event don't have any data
to have those you need to use other type of trigger
.share your config, Retentive
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
yea please
Yes. Instead of being drip fed tiny pieces of information.
Let's see it all in context.
rgr, wilco
what the hell does
mean
sorry, "rgr" = "Roger" = "message received", "wilco" = "will comply". Military speak.
๐
old habits die hard
Hello. Would someone please help me figure out fine tuning my blind template. It seems to work but Iโm getting an error in template UI. I actually have to templates that work sort of ๐ Im also using Siri which also works but there is some sort of a loop in HomeKit because the when give a command the blind does open but the Siri just keeps spinning.
@hollow rampart posted a code wall, it is moved here --> https://paste.ubuntu.com/p/rrMYWB3cjn/
This is what I have so far.
i was 100% off track @primal ledge , you should have send it before XD
What are you expecting to happen? You have a wait right at the end... that'll achieve nothing.
i will keep the automation 'running' i guess ...
'guess' ๐
@ivory delta, I removed the later steps so I could be sure the errors wasn't coming from them.
Well as written, I wouldn't expect it to work.
And if the template works fine in the Dev Tools, this is more of an #automations-archived thing.
The automation
Plus there are likely better ways to achieve what you're trying to do... but that's also a discussion to have in #automations-archived
I never end up posting in the right group. my bad.
agreed. will head over there. sorry for the noise
@hollow rampart
{% if states.light.left_blind_isy.attributes.brightness %}
on
{% else %}
off
{% endif %}```
please use `value_template: " {{ state_attr('light.left_blind_isy', 'brightness' ) > 0 }}"` or something like that first. calling state.light. ... will create error when the device is unknown
No problem. You have a template inside an automation, could've been either ๐
while I have you, is there a "correct" way to access that last_changed value in a template?
Ok Iโll try it thank you.
why do you use a light brighness to set the on off if i may ask ?
The way I suggested earlier, Retentive.
what ? where mono ? i missed it to
by the way mono, would you have any clue about #templates-archived message ?
Ok so my controller is ISY. All zwave light devices come in at 0-100. When I bring the blind data in from ISY HA things itโs a light. So I convert the light to cover domain. Than I want to fine tune the % open.
i actualy didn't see the difference and though you had just copy his exemple and said that it wasn't the right way XD
Sorry Iโm not sure if the question was for me?
it was :)
Ok good than you
thank's for the reason, it make more sense
@warped hill posted a code wall, it is moved here --> https://paste.ubuntu.com/p/Mwrnpg2Vhm/
but doesn't the 'light' on off state from your controler match the open/close state of the blind @hollow rampart ?
I changed the scale so that 0 is closed and position 100 in HA is actually 50% which is where the slats are horizontal.
any jinji2 expert here ? try to convert string to json
How to prevent json encode
{{ attr | tojson }}
avoiding using tojson ?
Yes but 50% is not perfectly horizontal so I was in the process of fine tuning by dividing position by say as an example 2.1 and so on.
I know in the template I have 2
but I need to process the data in json
oki doki @hollow rampart, hop you get it working :)
Thanks Iโll try your suggestion.
a blip in the system @primal ledge ;)
glitch in the matrix, yes
@warped hill i have no idea what you want to do, so i don't know how to help
i try to replace 'Voltage': 3.12, with 'Voltage': 5 .. any good way to do this ?
where 3.12 is variable
don't save attr as a string, but as a array, and override that value ?
how to make this states.binary_sensor[entity_id].attributes as dict ?
it is one when you get it
for exemple {{ states.media_player.tts_bureau.attributes }} return {'friendly_name': 'TTS_Bureau', 'supported_features': 65471}
so {% set attr=states.media_player.tts_bureau.attributes %} {% set attr['supported_features']=10%} i guess
would have to try it
it doesn't work @warped hill
@sinful bison so I tried the >1 change. So now when I close the blind it HA says it is unavailable which makes sense.
Why would you want to change the value of supported features?
TemplateSyntaxError: expected token 'end of statement block'
it's an exemple about how to change a value from a saved array @ivory delta
just assume. i want to change the value of attribute and publish via mqtt
set don't allow it, and we don't have do in home assistant
You can't manipulate the values of an entity using templates. I'm curious why you want to try to do it.
we are using template :)
The XY problem is asking about your attempted solution rather than your actual problem.
This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.
The problem occurs when people get stuck on what they believe is the solution and are unable to step back and explain the issue in full.
i try to replace 'Voltage': 3.12, with 'Voltage': 5 .. any good way to do this ?
I saw that. I'm asking why.
No, you don't. So stop answering for them.
mono. here is what i try to do. my device publish Voltage, Battery randomly
i try collect the update and combine them and publish back to mqtt
So the device gives bad data and you want to correct the data?
i want to update the attribute data
Okay. So just send your data directly to MQTT? Don't try to edit what's in HA.
eg current attr is "BatteryVoltage":3.04,"BatteryPercentage":100
then i receive update "BatteryVoltage":3.06
how to update to "BatteryVoltage":3.06,"BatteryPercentage":100
Update what?
Attribute
Where? What system? You can't update HA entities like that.
i cant just publist BatteryVoltage":3.06
Why not? What reads the value from MQTT?
if I publish BatteryVoltage":3.06. MQTT attribute will lost "BatteryPercentage":100
Ok... why does that matter? What reads the value from MQTT?
@sinful bison so I tried the change to the template and now if I move the slider anything past 1 the blind becomes unavailable.
it matter, i want to see both "BatteryVoltage":3.06,"BatteryPercentage":100 in attribute
Is value template more for if the unit is on or off? Or should I use position template.
@hollow rampart what integration are you using ? template cover right ?
If you can't tell me why it matters, I don't know how to help ๐
Thank you btw
Valid values are open/true or opening/closing/closed/false
so true false should return open and closed but not available and unavailable ...
Need as much information in attribute. "BatteryVoltage":3.06,"BatteryPercentage":100. The MQTT publish lots of things. If I dont do processing basically it all garbage in attribute
Whatever reads from MQTT should only care about the new information.
you did use value_template @hollow rampart and not availability_template
If missing information breaks it, your other software is the problem.
Fix your other software ๐
each few second, it publish "BatteryVoltage":3.06 then "BatteryPercentage":100 then LinkQuality":42
IF i can dig the hardware out
I never worked with availability template I can try it though
you don't need to, i just don't understand how this value changing make the device unavailable
Not every software is flashable ๐
Yeah, we're done here. Bye.
could you send me what {{state_attr('light.left_blind_isy', 'brightness' )}} return in the template page on the developement tool ? both with it at 0 and like 10 ?
i'll have to go eat, be right back ;)
@warped hill FYI when i do {{attr=states.media_player.tts_bureau.attributes}} attr is a mappingproxy, which don't have a setattr methode. You might want to see how to convert that type :)
When itโs 0 equals None and when it is 100% opened it gives me 50.
Which is correct.
been googling for 12 hours :D. i appreciate that
2 gives me 1 which makes sense since Iโm dividing by 2 and converting into int with round
i probably use regex_replace to replace the string ..Thanks for the help
{{ attr | regex_replace(''Voltage':.*?,', ''Voltage': 5')}}
i got it finally.. This is overly complex on jinja
@warped hill posted a code wall, it is moved here --> https://paste.ubuntu.com/p/SmvGmxhT4M/
@hollow rampart try again with {{ state_attr('light.left_blind_isy', 'brightness' )|int > 0 }} just in case, and if it still become unavailabe, i would like for you to do the same test in the template field, but with the full line and not only the first part.
if you are still around that is
I am encoutering something unexpecte with the change of template type.
I am trying to output the string 'None' but i always get an error string value is None for dictionary value @ data['option']
both with "{{ 'None' |string }}" and "{{ 'None' }}"
any idea why the template seam to return a None object rather than the string i ask ?
You should share the full config, Vlycop. Hard to tell what's wrong only from that error message.
To make is simple only the action is needed
action:
- service: input_select.select_option
entity_id: input_select.vitrine_swarovski_preset
data_template:
option: "{{ 'None' |string }}"```
the "real" template is more complicated but the issue is with the 'None' rendering since the above don't work
` option: "{{ 'None'|string if state_attr('light.vitrine_swarovski_segment_0','preset') != state_attr('light.vitrine_swarovski_segment_1','preset') else state_attr('light.vitrine_swarovski_segment_0','preset')|string }}"`
Hello so I took the initial template and instead of on or off I changed it to open or closed according to the cover template guide. Looks like itโs working.
Is that not the proper way to test for a string? Just checking.
i don't understand what you did, sorry. They was no string in the template
@hollow rampart posted a code wall, it is moved here --> https://paste.ubuntu.com/p/n2CDh6jWyk/
Ok this is what I changed
If there is a better way to do this I will follow your suggestion.
{% if states.light.left_blind_isy.attributes.brightness %} <- this is bad.
plus i have no idea what does the if check for
if the only issue is the word, i would use {{ 'open' if state_attr('light.left_blind_isy', 'brightness' )|int > 0 else 'close' }} but i am guessing what didn't work before was the if and not the word ...
I don't know why you're using |string everywhere, Vlycop. Most templates will return strings anyway.
And if you're quoting None, it's not the type None, it's the string 'None'.
@sinful bison I tried the above change and the error message is saying that Iโm missing a comma at column 35.
@ivory delta i have put |string everywhere because no mater what i try i get a type None
causing the error
If HA is converting 'None' back to None after it's evaluated the templates, you can't control that. Try with another word instead of 'None' that doesn't have a special meaning.
i can't ... i am getting the value from something i don't control :(
It's a bad idea (and often forbidden) in most languages to use keywords.
'None'|string is yours.
Use 'N/A' or 'banana' or something instead.
state_attr('light.vitrine_swarovski_segment_0','preset')|string retrurn None
Which is fine when it's inside the template.
the other bit is only to manualy set it to none if i get data that don't match what is expected
But it works in template editor. Geez
Your template can do whatever it wants. Once it's evaluated and the value passed to something else, the next thing will try to use the value.
you have a typo somewhere :( maybe i made one
It's apparently seeing 'None' from your template and turning it into None. That's not a problem you can solve within your template.
i'll open an issue to see if there is a drawback to block that convertion. This is new the the change of what type template return, it didn't happend in 116.
thank's
You're missing the point.
You're setting the value of an input_select, right? Instead of having an option called 'None', call it something else.
i'll have to convert the data both when i write it (here) and when i read it (another automation).
I can do that, but it's still not normal, if i want to send a notification with the word None, i should be able to do it.
Maybe the devs can think of a way round it. I can't. I agree that the new functionality makes some cases tricky, but they're not just going to undo the native types stuff they added.
off course they won't ! but this more like an edge case they didn't found than a deliberate choice
I think you're right to open an issue for it though. I've seen similar before, just not with keywords.
Well it's tricky. You either allow HA to interpret the result of a template as native types or you don't. I don't know how they could add any 'middle ground'.
You don't want 'None' to become None. Other people will. Can't do both.
Log an issue and at least it'll start a discussion with the devs ๐
i think that with the new way type are being send, you should send use None when you want it and 'None' when you need the string. We will see what they think of it when they have time
I think the issue is that Jinja returns a string and HA interprets it.
Remember, templates used to always be a string, even if what you thought you were returning was another type (dict/list/etc)
value_template: {{ 'open' if state_attr('light.left_blind_isy', 'brightness' ) | int > 0 else 'closedโ }}
Ok so this is what I typed in
It looks good but it is still telling me there is an error after open
Double quotes around the whole thing
Ahh
Rule #1
Got it
I thought that was "don't talk about #templates-archived"
Thank you everyone that works!!
Sorry i was busy with other thing, i didn't saw your reply
I have a template switch, which reads the value of a sensor and is on or off depending on that value. Now, I have two challenges :
-
When I manually flip the switch, it takes 10-20 seconds for the sensor to catch up. So what happens is that the switch flips back to the reverse position and then flip again. (eg. I turn it on, it then turns off within a few seconds and 10-20 seconds later turns back on again)
-
For whatever reason, the sensor sometimes has an insane value for a single reason. Because of this, the switch will flip to 'on' for 10 seconds (the sensor update frequency). So I'm wondering if there is a way to template the sensor reading "having been above X for Y seconds".
sensor.rpi_milksensor_script_process_1:
icon: mdi:application
icon_color:
templates: >
return (state === 's') ? 'rgb(67,167,47)' : 'rgb(219,27,8)';
please someone help what do i need to do its not working , have been trying for a week now.
this is in my customize.yaml
Do you have custom_ui installed? Where did you get that syntax from?
@inner mesa i think i have installed it , how can i check ? also i got it from previous discussions here in the group
am soo pissed man haha , a week, am trying not to be Spammy here in the group waiting patently haha
I donโt use it anymore. I think youโll see it somewhere in
-> Info
But youโd know if you installed it
i know i installed it ..