#templates-archived
1 messages ยท Page 94 of 1
Sorry, I misread something you said above. If the sensor has a value like 70 F | 40% you won't be able to see a graph with temp and humidity if that's what you're asking
oh ok
thats why people don't put them in the same line and make a card for temp & card for hum some times i think ๐
Anyone knows why isn't rendering?
{{ trigger.event.data.entity_id.endswith('sensor.17track_package_')}}
It's giving me UndefinedError: 'trigger' is undefined
Is this in an automation?
@mighty ledge Thank you โค๏ธ I hadn't attached a date. You fixed my problem.
@buoyant pine for the moment it switches between off an cool all the time... maybe because of the delay between the both. 1 turns cool but 2 is still off which troggers 1 to turn off again and vise versa. but your condition might be a good idea.. how would that conditon look like?
you mean like this for the multiple entites in trigger and automation:?
@olive moth posted a code wall, it is moved here --> https://paste.ubuntu.com/p/TsYbcnKKgb/
~rule6 @olive moth
@olive moth Rule #6: Spam will not be tolerated, including but not limited to: self-promotion, flooding, codewalls (longer than 15 lines) and unapproved bots.
Please take the time now to review all of the rules and references in #rules.
@hollow bramble it's supposed to be but it was erroring out in the logs with that error. So then was trying to test the individual conditions on the template tab and all give me the same error.
I got the automation from a thread in the community forum and from searching I've seen others use that type of template before but I don't understand the problem. And couldn't fine any breaking changes in case something had changes a while back
@fast mason testing it in the template tab wont work because you don't have a trigger object. It will only work in automation conditions or actions. Also, your testing the entity_id string with 'endswith' but the string appears to be the start of the entity_id. I would assume you want .startswith( instead.
@fast mason posted a code wall, it is moved here --> https://paste.ubuntu.com/p/XkcHfPzgT3/
oops was too big I guess.. It moved my text with it though ๐
at first I was assuming my trigger was the isssue rather than the templates but not sure
All, I could use a little assistance with a template. I think it's a yaml spacing issue, but I can't figure it out.
โ
That's your problem - "smart" quotes
Fix all of those, then run a config check
Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.
single quotes then?
I'm sorry, not familiar with smart quotes.
HA! Well, in all fairness I cntrl-v/cntrl-c from the community... So, no clue how he got it to work... but thanks for the headsup, I wasn't even aware there was a difference.
Hello
@lunar osprey posted a code wall, it is moved here --> https://paste.ubuntu.com/p/YZkhK6X7qc/
This is working
@lunar osprey posted a code wall, it is moved here --> https://paste.ubuntu.com/p/B8K3XT4pSF/
tap_action:
action: call-service
service: vacuum.send_command
service_data:
command: clean
entity_id: vacuum.aspirapolvere
params:
act: 'start'
content: '2'
count: 2
type: 'spotArea'
type: state-icon
but in this way... it's not working
vacuum_clean_zone:
alias: Pulisci zona
sequence:
- service: vacuum.send_command
data_template:
command: clean
entity_id: vacuum.aspirapolvere
params:
act: 'start'
type: 'spotArea'
count: >-
{%- if is_state('input_boolean.deebot_times', 'on') -%}{{2|int}}{%- else
-%}{{1|int}}{% endif %}
content: >-
{{-states('input_text.idstanze')[:-1]}}
I got 'count': '2'
instead of 'count': 2
without apex
how can I set the template to send an integer
instead of a text?
~rule6 @lunar osprey
@lunar osprey Rule #6: Spam will not be tolerated, including but not limited to: self-promotion, flooding, codewalls (longer than 15 lines) and unapproved bots.
Please take the time now to review all of the rules and references in #rules.
Try
{{ "2" if is_state('input_boolean.deebot_times', 'on') else "1" }}
@thorny snow That guy posted unformatted code in the forum, so all bets are off.
Is there a quick way to grab the "condition" i.e. cloud, wet, sunny from the forecast from the weather sensor? I'd like to get tomorrows data from the forecast but I'm having trouble accessing attributes inside {{ state_attr('weather.the_retreat','forecast') }}. This is using NMI the default Home Assistant weather provider.
Probably that's an array
Try the following in
-> Templates
{{ states.weather.the_retreat.attributes.forecast }}
it doesn't work...
count: >
{{ "2" if is_state('input_boolean.deebot_times', 'on') else "1" }}
I get: {'act': 'start', 'type': 'spotArea', 'count': '2', 'content': '2'}
I should get instead: {'act': 'start', 'type': 'spotArea', 'count': 2, 'content': '2'}
Unfortunately the integration really needs to handle getting a number in quotes. I'd open an issue against it
shall I open a bug to vacuum component then?
That's what I just said ๐
ok
Try the following in
-> Templates
{{ states.weather.the_retreat.attributes.forecast }}
Thanks @arctic sorrel. I tried similar but I was using the {{ states('') }} method. Using your suggestion I can dial in perfectly. Thank you. {{ states.weather.the_retreat.attributes.forecast[0].condition }}.
Thanks @arctic sorrel. I tried similar but I was using the
{{ states('') }}method. Using your suggestion I can dial in perfectly. Thank you.{{ states.weather.the_retreat.attributes.forecast[0].condition }}.
@fiery ravine here is a working example https://github.com/jcallaghan/home-assistant-config/issues/87#issuecomment-638384212
@fiery ravine And you tagged me in that because ... ?
My apologies, just closing the loop.
hi all! I require some assistance with getting a reading out from command line sensor. When I manually type to commandline for example cat /dev/ttyUSB0 it gives me correct string. Hexdump returns me the actual hex values I want. But when I try to setup a command line sensor to get the reading to show up in UI I get unknown always... what am I doing wrong?
How did you install HA?
I am using latest HassOS on Rasp4. I installed according to latest instructions from official website
You'll want to check that your USB device is passed through - #330990055533576204 can help there
Thanks I'll ask them
Hello one question: I have created an input bolean for my letter box telling me if it is full or after I fetched the mail empty.
In fact, it tells me on or off. Is it possible to change the possible states to full or empty instead of on or off, or is it possible to at least display it differently in Lovelace? Thanks for your help
With a template sensor, sure
value_template: "{{ 'Full' if is_state('input_boolean.mailbox','on') else 'Empty' }}"
Ok nice thanks very much for that approach, will give it a shot
Hello, can i have one question, i try to setup an automation for my vacuum that allows me to choose multiple rooms for segemented cleaning (aka room cleaning). Entities are input_booleans that manually assigned room_id parameter in customize.yaml. At the end this is what gives a parameter value in a data_template{{ roomIds.split(',')|map('int')|list }} This template returns a list of integers and my service call gives this error Unable to send command to the vacuum: {'code': -10005, 'message': 'data for segment is not a number'} but in other automation this is how i pass this variable manually and this just works fine
`
- service: vacuum.send_command
data:
entity_id: vacuum.xiaomi_vacuum_cleaner
command: app_segment_clean
params: [19,20,23]
`
Anyone have a solution for this maybe?
Hi, mates!
Is there any way to test in a wait_template, a sensor for being less than X, for longer than Y seconds?
example:
{{ states('sensor.shp7_cozinha_potencia') | int < 300 for 00:00:30 }}```
{{ (states('sensor.shp7_cozinha_potencia') | int < 300) and ((now() - states.sensor.shp7_cozinha_potencia.last_updated).seconds > 30) }}
``` probably
I think the second part of that statement will be always false as the sensor updates every second with a new value, regardless which is. :/
Then you need to create a template binary sensor that's on when it's below 300 and off above, and use the state of that
Thanks!
Can anyone take a look at these templates from my config? The first two are working, but the bottom three are not and I can't spot the difference. (I literally copy and pasted and changed a '_type_2' to a '_type_3'
https://paste.ubuntu.com/p/RQRNnkYsFf/
I'd suggest checking the states to see if they do what you think they do.
> States, and find those entities.
When working with templates, don't forget:
- You can test them in Developer tools -> Templates
- Rule 1 and rule 2 (https://www.home-assistant.io/docs/automation/templating/#important-template-rules)
You can also put all of those sensors under one - platform: template
{{ state.attributes.Days-until }} with what do you need to replace the '-' with? can't find in documentation maybe i am blind
Is the attribute Days-until?
yes
That's... unfortunate
"{{ state.attributes['Days-until'] }}"
Maybe {{ state.attributes[Days-until] }}?
There we go, somebody who groks more than me
if not in quotes it tries to substract untill from Days
and look for the result of that substracion (which will fail) as a key in the attrributes
Value cannot be processed as a number that is really weird
yes with the quotes
are you using the template tester?
Sounds like we are missing some part of the information here, or rule 1 of templating was not folowed ๐คทโโ๏ธ
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
the entire thing
IC
that paste doesn't have any of the changes we suggested
"{{ state_attr('sensor.mijnafvalwijzer_restafval', 'Days-until') | int }}"
same problem sadly
test that in the template tester
Then you did not paste it the same way
yaml is not a programming language, and templates are not python
ah i got it to work
used my own text editor instead trough ui
until yesterday i had never did do any yaml or python
And you still haven't done any python ๐
what did i copy paste then?
a jinja template
yaml that contains a jinja2 template
well somehow it looks a little bit like razor
is there a mechanism with which I can convert data provided to my service into a JSON payload for a rest_command I'm building?
@misty pasture you can print objects passed as a JSON. for example your service data could be:
{"payload": {"foo": "bar", "xyz": 123}}
Then you just need to use {{ payload | tojson }} as your payload
Hello, I'm not sure if i'm here right. But my question is: I have setup glances on several systems. I can get the uptime of the servers as strings in the format: "73 days, 22:52:39". Is there any chance to get it displayed as "73d 22h 52m"
so I want to have multiple device_tracker entities displayed as on/off instead of home/not_home
Is there a generic template way to make this happen or do I need to create templates for each of them? (20-30 entities)
Template for each one
@arctic sorrel can you please stop always being so correct, I don't like to do hard work ๐
oh well someday one will be able to just do cosmetic things like this via the frontend I hope
How should I modify this to make it evaluate the same as color: "blue"?
name: Send One Blue
tap_action:
action: call-service
service: my_service
service_data:
payload:
color: >
[[[
return "blue";
]]]
count: 1
type: button
Can someone help me with this binary_sensor?
sensors:
living_room_occupied:
value_template: >-
{{ is_state('binary_sensor.front_door', 'on')
or is_state('binary_sensor.living_room_1_motion', 'on')
or is state('binary_sensor.living_room_2_motion', 'on') }}```
I'm sure I'm way off but I cant find any examples online
I dont know its not passing the check
what's the error
You need an if
also test the template at developer tools > template
Whatever
you don't need an if, you can do a statement like that
Invalid config for [binary_sensor.template]: invalid template (TemplateSyntaxError: expected token 'end of print statement', got 'state') for dictionary value @ data['sensors']['living_room_occupied']['value_template']. Got "{{ is_state('binary_sensor.front_door', 'on')\n or is_state('binary_sensor.living_room_1_motion', 'on')\n or is state('binary_sensor.living_room_2_motion', 'on') }}". (See ?, line ?).
oh it doesn't like the newlines
Ahhh should it have just been a comma
try it all on one line
Ok
oh wait
nope. is state on the last line
needs to be is_state
didn't even see that until now lol
@inner mesa this is an example of a template i use in a template binary sensor:
"{{ is_state('sensor.xbox_status', 'Available') }}"
the template just needs to result in True or False, you don't need to specifically use an if/else statement
is using as_timestamp(now()) in a template an issue?
some reason i feel like i've read not to do that
n/m it's in the examples so I am going to go for it
Trying to get an icon to change based on the state of a template sensor, can the sensor point to itself for the icon change?
sensors:
sprinkler_ban:
friendly_name: "Sprinkler Ban"
value_template: >-
{{ now().month >= 6 and now().month < 9 }}
icon_template: >-
{% if is_state("sensor.sprinkler_ban","true") %}
mdi:water-off
{% else %}
mdi:water
{% endif %}
Recursion is generally a bad idea unless you know what you're doing.
See this link for an example: https://discordapp.com/channels/330944238910963714/672223497736421388/719189662257774682
Also, why not just use the expression you've already worked out (now().month >= 6 and now().month < 9) in both parts?
Ok thanks, will give that a go, honestly didn't even think of it.
6 <= now().month < 9
Would someone happen to know why this is happening? I've made a date sensor but for some reason it sometimes doesn't update. Here it went from 3-6 to 7-6 because I restarted HA: http://werra11.eu/i/07-06-2020_19:30:05.png. Using following config:
- platform: template
sensors:
dagmaand:
friendly_name: Datum
value_template: >
{{ now().day }} - {{ now().month }}```
See the note on now() toward the bottom: https://www.home-assistant.io/docs/configuration/templating/
Ah I see now, thank you!
Can someone please write me a template that checks if a sensor is greater than 0?
{{ states('sensor.brains')|int > 0 }}
Thanks
Long time no see, clippy
Heh
Hi all, how can I use a template inside a template? The 'myattribute{{ i }}' part is not working:
{% for i in range(11) %}
{{ state_attr('sensor.mysensor', 'myattribute{{ i }}') }}
{% endfor %}
Do you want it to be e.g. 'myattribute1', 'myattribute2' etc?
yes
What you want is called "string concatenation".
{{ state_attr('sensor.mysensor', 'myattribute' + ( i | string ) ) }}
You need the | string because you can't add an integer to a piece of text, but if you turn it into text first, then the program will know what you meant.
Oh, I see, thank you. I was trying to concatenate {{ i }} instead of ( i | string )
I'm using ha dockermon and trying to get CPU stats for my docker containers. I use this for the memory stats but was hoping someone could help with CPU?
- platform: rest
resource:
http://192.168.68.110:7777/container/ha_dockermon/stats
name: HA Dockermon Memory
scan_interval: 900
value_template: '{{ (value_json.memory_stats.usage /1024/1024) |round(2) }}'
unit_of_measurement: 'MB'
- platform: average
name: ha_dockermon_memory_average
entities:
- sensor.ha_dockermon_memory
duration:
days: 2
can I use a template in json in a service node? I tried this and it doesn't work.
{
"entity_id": [
"light.dining_room"
],
"brightness": "{{states('sensor.rotary_encoder')}}",
"xy_color": [
0.37,
0.372
]
}
@velvet gate if the service itself does not support templates, you should use data_template instead of data
well I'm using a service node in node-red and doing light.turn_on
#node-red-archived would be a better place to ask
rah
can i use template in a trigger to compare a numerical value?
https://paste.ubuntu.com/p/6qZc5Qw33p/
i believe it's line 4-5 that's giving me issues
value_template: "{{ states('sensor.current' > 0 }}"
^
``` 
When working with templates, don't forget:
- You can test them in Developer tools -> Templates
- Rule 1 and rule 2 (https://www.home-assistant.io/docs/automation/templating/#important-template-rules)
thank you! will have a look
) will certainly help
so that page leads me to believe that i should use numeric state trigger
but i don't understand the valuetemplate part of the instruction
value_template: "{{ state.attributes.battery }}"
where do i deduce what i should be using? state.attributes.current?
alias: 'Turn off charging if electricity is expensive and car is charging'
trigger:
- platform: numeric_state
entity_id: sensor.current
value_template: "{{ states('sensor.current' }}"
above: 0
it's questionable if it's even necessary
That value template returns the state of the entity, it's pointless
If sensor.current has the value you need for the state, that's all you need
then this should be fine:
- platform: numeric_state
entity_id: sensor.current
above: 0
Sure
now the only issue is my delay
i mean how can i be getting this wrong
- id: '12'
alias: 'Turn off charging if electricity is expensive and car is charging'
trigger:- platform: numeric_state
entity_id: sensor.current
above: 0
condition: - condition: template
value_template: '{{ is_state("sensor.tibber_price_level", "EXPENSIVE") or is_state("sensor.tibber_price_level", "VERY_EXPENSIVE") }}'
action: - service: switch.turn_off
entity_id: switch.innr_plug - delay:
minutes: 2
- platform: numeric_state
that's the full automation, the delay section still gives errors but it doesn't make sense. I've seen atleast 4 examples using it the same way
tried it with - delay: "00:02:00" as well
Invalid config for [automation]: [minutes] is an invalid option for [automation]. Check: automation->trigger->0->minutes. (See /config/configuration.yaml, line 12).
~share @tawny coral
@tawny coral Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
That error has nothing to do with that automation
really? because if i remove the delay it doesn't give an error
aha i got 2 minutse errors
I'm not sure why you'd have a delay as the final action though ๐คท
If you can correctly format your code, it'll be easier to see what's a formatting error and what's not ๐
aha i didn't know it mattered where in the action it was. obviously it should wait 2min and then turn off

Obviously the order matters...
a sequence of actions that Home Assistant will execute
Otherwise, how would things like delays and wait templates work?
in my would the delay would be assigned to the service or whatnot, be nested inside of it but yeah. I'm silly ๐
I'm trying to get a value template from the following
"cpu_stats":{"cpu_usage":{"total_usage":323907770833
I have this so far but keep getting an error value_template: '{{ (value_json.cpu_stats.total_usage }}'
Can someone point me in the right direction please?
https://paste.ubuntu.com/p/xykqchccHN/ this is that doesn't work but the error message didn't make sense to me until you told me that it was a different place
so i just changed it to time_pattern instead of time and voila ๐
Is there a way to get this number 323907770833 which is CPU usage into a more user friendly number? I'm using a value template but not sure what to add to it?
'{{ (value_json.cpu_stats.cpu_usage.total_usage) |round(2) }}' the number it outputs as a sensor at the moment is 326742444571.0 %
that doesn't look like cpu usage.
If that's a percentage, that's got a lot of CPUs
Hey
Deploying latest ova in vcenter
Issues detected with selected template. Details: - 23:5:PARSE_ERROR: Parse error: Undeclared namespace prefix "vmw" (for attribute "osType") at [row,col,system-id]: [23,74,"descriptor.ovf"].
this channel is for jinja2 templates. i don't think what you are looking at is that
Looks like a #330990055533576204 thing
With https://www.home-assistant.io/integrations/version/ I can get the Hassio version but how do I get the current and available version of HassOS?
supervisor -> system -> host
can i get this in to a sensor?
Sure, there are a few guides on the forum for it
Got a link to the morning's chat ๐
If you search @thorny perch you'll find a chat from earlier ๐
on this channel?
Just search hassos version
can you if elif a delay?
would be in a script
Same channel ๐
I am having a similar issue to the one in this post https://community.home-assistant.io/t/template-sensor-feedback-delay/92482 I use a broadlink RM mini 3 to turn on and off my A/C from HA and a Wyse sensor as a binary sensor to determine the current state (as it may already be turned on/off from the original IR remote). I am using a template switch but when I turn it on in HA the switch immediate returns to the off position until the binary sensor triggers and it then displays as on again. Is there any way to add a delay to the trigger from the binary sensor so it doesn't go ON -> OFF -> ON everytime I turn it on?
I'm troubleshooting a template in the templating tool. Can I set the current time/date within the tool for troubleshooting?
{% set now() = dd:mm:yy hh:mm:ss %} I know that's not right but something like that. I want to set various times and see where my template is falling down.
@glacial sail you can use the for option for the trigger so teh sensor must be on for x amount of time before the automation triggers...not sure if that is what you are looking for? more of a #automations-archived question too if thats the route you want to go.
@sinful ridge see if this page helps https://www.home-assistant.io/docs/configuration/templating/#time
Ha, so my template is correct! The frontend is displaying something other than what the value template is calculating 
Off to #frontend-archived ๐
is there a simpler way to compare if "somedate" isn't today compared to
{% set somedate = '2020-06-08T15:48:00' %}
{{ as_timestamp(somedate) | timestamp_custom ('%j') != as_timestamp(now()) | timestamp_custom ('%j') }}
Thank you, that's what I needed. Then I could put "somedate" into my value template I was working on in place of now() to see how it would behave at different times/dates.
glad to be of accidental help ๐
Turns out my issue was the value template was a time difference and it wasn't updating as often as needed. Adding in entity_id: sensor.date took care of it.
Haha, yes!
I just assume everyone is talking to me.
please could i get some help, been scratching my head all day searching the the forums. im looking to set the duration of a timer but for some reason i cant get it to recognize.
{{ states('input_number.cooking_hours') | int }}:{{states('input_number.cooking_minutes') | int }}:00
@dull pecan 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
action:
- data:
data_template:
duration: '{{ states(''input_number.cooking_hours'') | int}}:{{states(''input_number.cooking_minutes'')
| int}}:00'
entity_id: timer.cooking
service: timer.start```
What happens if you specify the duration in seconds instead?
@ivory delta im not sure what you mean
duration accepts either a string in the format HH.mm.ss or an integer specifying the number of seconds.
But I don't think that's the problem. duration should be at the same level as entity_id.
ah i see, so i was trying to use two sliders from the frontend as the timer could be used for a number of hrs
- duration: '{{ states(''input_number.cooking_hours'') | int}}:{{states(''input_number.cooking_minutes'')
| int}}:00'
entity_id: timer.cooking
service: timer.start```
Assuming it accepts a template.
action:
- data_template:
duration: '{{ states(''input_number.cooking_hours'') | int}}:{{states(''input_number.cooking_minutes'') | int}}:00'
entity_id: timer.cooking
service: timer.start
``` try that
The problem is you had data and then data_template
I suspect if you look at the logs you'll find it complaining
Thanks @arctic sorrel this did the trick, i had already removed the data section before with no joy as i had read this in the forum. but this time of trying i carried out a system restart then hey presto the timer is running
Tinkerer is the king of templates (and most other things) ๐ฆ
I can fake almost anything with enough help from the bot ๐
Its like magic, sadly im not in the IT game and sometime struggle when it comes to the raw code aspect of it. im grateful for the help and direction
It's mostly just "follow the rules"
With the occasional dash of magic and/or chaos
I'm trying to get an average of temperatures (states('sensor1') + states('sensor2')) / 2 but it's join the two states as strings. parseInt doesn't work to add them ass ints. Any ideas?
dev work is sorcery
https://www.home-assistant.io/integrations/min_max/ @gritty radish
Is it possible to use a variable for the target on alexa?
data:
type: tts
message: >
Here is your status update for today.
target:
{{ states('input_select.alexa_update_device') }}
Possibly, if correctly structured
Become a real Jinja2 Ninja! Don't worry my Genin, we are here to help! You can find the docs at https://www.home-assistant.io/docs/automation/templating/ - and don't forget rule #1! Please use https://www.hastebin.com/ or https://paste.ubuntu.com/ to share code or logs
You need to use data_template
doh! you're right.
thanks
i've been looking at this for hours, it's nice to have the pointer
hey
i am struggling with an integer thing inside a script
is there anyone that can help ?
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?
ok then
i have this
switch_on_light_office:
alias: switch_on_light_office
sequence:
- data_template:
brightness: "{% if is_state('input_number.office_light_state', '3') %}
255 | int
{% elif is_state('input_number.office_light_state', '1') %}
30 | int
{% elif is_state('input_number.office_light_state', '2') %}
0 | int
{% endif %}"
entity_id: light.bureau
service: light.turn_on
not sure it s the best way to write it
but the intention was to make different action when i press the on button on my wall switch
and then i got this issue
expected int for dictionary value @ data['brightness']
and then i didn't find the key in forum and documentation
- data_template:
brightness: >-
{% if is_state('input_number.office_light_state', '3') %}
255
{% elif is_state('input_number.office_light_state', '1') %}
30
{% else %}
0
{% endif %}
or
- data_template:
brightness: >-
{%- set map = {'3': 255, '1': 30} -%}
{{ map.get(states('input_number.office_light_state'), 0) }}
might as well make the bot happy
unless that is one of the ones that is dumb and won't auto-cast the output to an int for you
@arctic sorrel cool
Tinkerer is away for 20m 17s with a message :point_right: Heading towards the second star to the right
thx
@dreamy sinew thx too
i m just discovering how input_number is working
and it s not as expected
i thought the service input_number.increment
would change the value according to the min and max
like
min: 1
max: 3
step: 1
if the value is 3 i thought input_number.increment would set the value to 1
but i guess its not the case
Hi all. Can I get your input on https://community.home-assistant.io/t/help-with-yaml-spacing-for-a-simple-template-binary-sensor/203562. Thank you muchly. ๐
Everything under living room needs to be tabbed over by 2
thanks @dreamy sinew - spaces or tabs?
spaces
Someone responded on your post with the correct answer
thanks. seems to have worked. every time I think I'm getting close on spacing something seems to throw me.
Friendly name, value template, and class are all properties of the living room entity
They need to be a level deeper than living room because of that
once you mention it it makes sense certainly - the issue is coming up with that out of my own head on the fly
by the way, been working on HA for a while now and have always appreciated how quite helpful and efficient the community is, so kudos ๐
- platform: rest
payload: '{"query":"{\r\n Queue(date_from: \"2020-05-29 08:00:00\", date_to: \"2020-05-29 17:00:00\", ......
Can I put todays date in here somehow, instead of 2020-05-29?
{{ as_timestamp(now()) }}
Though probably need to go a bit further to pull out just the date
yeah, seems like now().strftime('%Y-%m-%d') might do the job. Although it's over midnight now, so i have to wait until 8 am to see if it works. ๐
Thanks.
Np
@glacial sail you can use the
foroption for the trigger so teh sensor must beonfor x amount of time before the automation triggers...not sure if that is what you are looking for? more of a #automations-archived question too if thats the route you want to go.
@charred haven I use node red for my automations but I will look into automations in HA and see if I can use them to solve my problem. Thanks.
try asking #node-red-archived for the equivalent of that option
could anybody help me out? I don't know if links are allowed, but I made a reddit post asking about it and i've got no response so far: https://www.reddit.com/r/homeassistant/comments/gzw4i1/template_value_not_updating/
oh my gosh thank you. I've been skimming over this document multiple times and must have missed that. Thank you!
Np, took me a bit to re-find it
wait as im reading this i just realized I was only reading //templating (https://www.home-assistant.io/docs/configuration/templating/). Why would those be so similarily named and not reference each other?
is there any way of using a template for entity_id? I would like it to just include every person object (for example person.bob, person.jim, etc) without me having to manually update it every time a new person is added
@keen smelt you can iterate states.person
yes I have a template created, but i'm getting an error message because it's trying to interpret the jinja data as a string
For example
{% for state in states.person -%}
{{ state.name | lower }} is {{state.state_with_unit}},
{%- endfor %}
how do I paste code in discord? Ill show you my config
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
Putting that into the template tester in Developer Tools works fine for me
What are you trying to achieve with the template?
im trying to create a template variable that counts the total number of people "home" and sets it. In order to update it though, I need to set the entity_id value to each person
but I don't want to manually add a person each time, so I'm trying to do a template for it
Here is my current template sensor config: https://paste.ubuntu.com/p/fPkrRf8C6N/
entity_id optional for templates - it's usually able to be automatically implied based on the template which entities will trigger a refresh
It's not for my case though, which is why I'm doing this
entity_id doesn't itself support templates, so you'd need to hard code it
that's what I was thinking, but I wanted to see if there was another option
Let me check the code for the template helper, it should be able to pick up that states.person depends on all active person entities
You need to drill down to a specific entity
The code is looking for states.domain.entity_id or states(entity_id) specifically
You can't iterate over a list of IDs either
If you can't do that, listing out your entities via entity_id: will ensure it will update when any of those entities changes
what do you mean by drill down to a specific entity?
Via the 2 methods in the line that came right after that comment
I'm on mobile so I don't want to type that out again
in other words - you'll have to hard code entity ids either in the template or in entity_id, so take your pick ๐คทโโ๏ธ
The watcher needs something deterministic for performance reasons
so a template would be to resource heavy?
It can be if you're bad and write a template that hits literally every entity
This is a way to take the shotgun away
You still have a sharp ax though. You just can't shotgun your foot off
๐คฃ to be fair I can't imagine you're creating and removing new person entities every day?
no I'm not but I'm the kind of person that loves automating things even if I do them once
and this project is teaching me a lot about templating so I'm just testing my options at this point
thank you guys!
Np!
There are some hacks that can be done but you're still listing out every entity somewhere
Automation isn't always the answer ๐
phew that last line shows me I need to understand filters a bit more haha
Lol
The reject was a recent addition. The battery in one of my sensors died and it tanked the average
Note that in the list of sensors I'm doing the states() call on the entity directly. If you don't do it that way, you'd have the same problem
I found that the hard way
yeah I was having trouble with that because those functions for my application (where I didn't have any direct references because it was looping through states.person) I couldn't do it that way
unless I missed something
Yep, that's the issue
true thats what I meant
Also, protip use states('person.person_1') as much as possible
yeah I totally will when I'm configuring definite things
If you use the other method and the entity doesn't exist on startup ha will throw exceptions
states() will just return unknown
thats really convenient
If im doing a value template that take differences of times I need an entity to trigger the value to calculate it on a regular basis. But what about when using the template editor in dev tools? Is it constantly reevaluating time or do I need to manage that somehow?
Every time you edit the template there it updates the template
So, adding a space causes it to be updated
Cheers, good to know.
Im using the below in an automation, is there a way to format the text of the friendly name to use all or partial capital letters?
message: "Check: {{ state_attr(trigger.entity_id, 'friendly_name') }}"
|title
Im assuming like below?
message: "Check: {{ state_attr(trigger.entity_id, 'friendly_name|title') }}"
@dreamy sinew tested and functions as expected. thanks!
Currently, my setup: I am sending this:
curl -d 'testdata=1' -X POST https://[mydomain]/api/webhook/testy
Which works if i have no condition. I am trying to setup the condition per the docs ( whcih don't mention how to parse the data coming in from the web hook in the Conditions, Automation templates, and Automation conditions pages that I can see, if i am blind, please correct me.) with the following condition:
condition: template
value_template: '{{ state_attr("trigger.data", "testdata") < 4 }}'```
also tried using curl -d '{"testdata":"1"}' and swapping out for trigger.json with no luck. What am I doing wrong?
@pearl bough , you will prob get more help sharing the whole automation
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
Try "{{ trigger.data['testdata'] | int < 4 }}"
@pearl bough โ๏ธ
Scared them away I guess ๐ข
He is prob trying it ๐๐ป
Yeah I'm jk lol
Hm, is the syntax different for json?
For trigger.json? Prob the same
trying {{ trigger.json['testdata'] | int < 4 }} with curl -d '{"testdata":"1"}' doesn't seem to work
hm, maybe i need to pass on an explicit json content type, sec
that didn't work.
tried: curl -H "Content-Type: application/json" -d '{"testdata":"1"}'
oh wait, i'm a dingus
i forgot to hit save
However, just redid some testing
I need that Content-Type header added for the trigger.json to behave
Makes sense
Fun fun fun, now i can make various web stuff of mine trigger stuff ๐
ty for the pointers!
Donโt do anything Tediore wouldnโt do. ๐คฃ
Would I need a template cover to extra data from this 19:35:13 {"TuyaReceived":{"Data":"55AA0307000507040001001A","Cmnd":7,"CmndData":"0704000100","DpType4Id7":0,"7":{"DpId":7,"DpIdType":4,"DpIdData":"00"}}}
debating if I can get away with MQTT cover
Hi all,
I'm checking my sensors template but don't find the mistake
if anyone as an idea?
- platform: template
sensors:
prod_sma_actuelle_watt:
value_template: >
{{ states.sensor.sma_power_absorbed.state - states.input_number.prod_minuit.state }}
unit_of_measurement: 'W'
It might help if you were to explain the problem ๐
That's because too many people have thought that sharing text as image is a good thing
It's not
input_number.prod_minuit : 33334714.0
When working with templates, don't forget:
- You can test them in Developer tools -> Templates
- Rule 1 and rule 2 (https://www.home-assistant.io/docs/automation/templating/#important-template-rules)
sensor.sma_power_absorbed : 33335460.0
You've tested the template โ๏ธ ?
sensor.prod_sma_actuelle_watt : unknown
i didn't test
will check didn't know that possibilities
but it's not in automation , this is in sensor template
@arctic sorrel in templates to test i enter :
today prod is {{ states.sensor.sma_power_absorbed.state - states.input_number.prod_minuit.state }}
response : unknown error rendering data
There you go - your template isn't valid ๐
{{ states('sensor.sma_power_absorbed')|int - states('input_number.prod_minuit')|int }}
``` Try that
it works !
thanks i'm a noob since i use home assistant since 2 weeks now .. ๐ฆ
thank you very much
No worries
good to know that i can test before to use, many times to win ๐
thanks from belgium ๐
Hi, trying to setup an automation that notifies me of updates to home assistant and hacs via a template. is there a way to combine this and show both If available? I am currently using the below and it is only showing hacs and not the current home assitant update.
message: 'Check: {{ state_attr(trigger.entity_id, ''friendly_name'')|title }}'
title: Update Available
service: persistent_notification.create
Anyway to invert 0-100 to 100-0 scale
i.e. 2 -> 98
5 -> 95
It would be f(x)=100โx
I'll think this is it:
{{ 100 - states('sensor.living_room_blind_position') | int}}
It is ๐
Can "this" be used with templates to remove to the current state of the object?
you'd ahve to make a template sensor
I am trying to pull the 'status' attribute from my robot vacuum for an automation. This is what I have so far, but it does not seem to be working. I've tried for a few hours tweaking... but hoping its something obvious? {{ state_attr('vacuum.robovacโ,โstatusโ) == 'cleaning' }}
is "cleaning" ?
granted cleaning is one of the statuses
what exactly are you trying to get?
"smart" quotes
๐คฎ
{{ state_attr('vacuum.robovacโ,โstatusโ) == 'cleaning' }}
^ ^ ^
yeh, idle or cleaning. I'm trying to do an automation, basically
Trigger: When battery is below 60%
Trigger: When status is โreturningโ
Trigger: When status is โcleaningโ
Action: Turn on Eufy Power Plug
When working with templates, don't forget:
- You can test them in Developer tools -> Templates
- Rule 1 and rule 2 (https://www.home-assistant.io/docs/automation/templating/#important-template-rules)
Fix the "smart" quotes and then test ๐
Ohhh, how on earth did i not notice that! haha. My eyes are going square!
{{ is_state_attr('vacuum.robovac','status','cleaning') }}
what are "smart" quotes?
https://practicaltypography.com/straight-and-curly-quotes.html @jagged obsidian
i'm also blind, i dont see the difference .D
you gotta look closely.... it kinda has a little dot at the top
Anybody using a word processor will get โsmartโ quotes
but so easy to miss
As opposed to "simple" quotes
but now i know, i'll definitely watch out for those
โ " โ
ah now i know what you mean... still didn't spot that difference ๐
time to get new glasses
๐
Me: time to get new eyes
my brand!
I have a problem with rounding my template sensor.
That is a there is a problem in the system statement
Hello, coming ove rfrom automations ๐
im trying to trigger an automation based on a template.
I have a helper type input_datetime that only uses time
and i created a sensor sensor.time
but the sensor.time outputs time as H:M
and my helper outputs in H:M:S
now im unable to compare those in a template
@meager orchid 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
that's a new one
https://www.home-assistant.io/docs/configuration/templating/#time @glacial root - timestamp_ converts a timestamp not a string ๐
- platform: template
sensors:
shower_hum_over_eighty:
friendly_name: "Shower Humidity Over 80%"
value_template: >-
{% if states('sensor.bath_humidity') | float > 80 %}
on
{% else %}
off
{% endif %}
so i probably have to use strptime ? @arctic sorrel
There we go - not suer what happened. Anyway - I can't get this sensor to turn on - despite the humidity going above 80%
you using a sensor or a binary sensor?
binary
value_template: "{{ states('sensor.bath_humidity')|float > 80 }}"```
so just nix the % symbols and put the whole line in quotes?
Exactly as shown there - replaces your 6 lines
ok thanks - any idea why my version works in the Templateing section - but not in "real life"?
binary sensor is expecting true/false
which you can do via your method but its not necessary
ok great, appreciate the assist
I think this is where this belongs but I have imperial units selected in the UI as my default which is what I want for everything expect the Temps from my Netdata integration which I want in Celsius. Other than template is there an easy way to do this?
@arctic sorrel i managed to get it to work. It ain't pretty. but it works:
- platform: template
value_template: '{% if states(''sensor.time'') == (states(''input_datetime.wanneer_nieuwe_herinnering'')[0:5])
%}true{% endif %}'
Eh, if it works... it's not how I'd have done it, but it's valid ๐คท
haha, well i wanted to use strptime but couldn't get it to work
Could you tell me how you would have done it? so I can learn from that?
I'll dig out an example later and ping you when I've got it ๐
thx! ๐
21:49 (this was the string from sensor.time)
21:22:00 (this was the string from input_datetime.wanneer_nieuwe_herinnering)
{{ states('sensor.time') == state_attr('input_datetime.wanneer_nieuwe_herinnering','timestamp')|timestamp_custom("%H:%M") }}
@hexed falcon you get a choice of imperial or metric for the entire system. you can't change individual entities
That's what I thought that sucks! Guess I'll just trick it with a template then
Could anyone help me configure a template switch to effectively change the domain of a light? I want to create a template switch which simply turns a light on/off but will be considered a "switch" instead of a "light."
`# Switches from samsung plugs that appear as lights
switch:
- platform: template
switches:
Bedroom Fan:
turn_on:
service: light.turn_on
data:
entity_id: light.on_off_output_4
turn_off:
service: light.turn_off
data:
entity_id: light.on_off_output_4`
That is what I attempted but isn't working
Should be fine
I have never made a template before, so literally all I've done is plop that into my config.yaml, not sure if I need to do something more... I got a config error on restart
I'm trying to do a more simple version now like this `# Switches from samsung plugs that appear as lights
switch:
- platform: light
name: "Bedroom Fan Samsung"
entity_id: light.on_off_output_4`
Also doesn't seem to work
Oh, I see. Change Bedroom Fan: to bedroom_fan:
So if this worked I should see a new entity named "bedroom_fan" which is a switch and controls that light called light.on_off_output_4 right?
Yup
It told me `The following integrations and platforms could not be set up:
switch.template
Please check your config.`
Bot is ded
lol
Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.
There we go
So I'm trying to create a template where the input value from a temp sensor, dictates the fan speed of my hvac. Does this look ok?
Hey folks, is there any easy way to translate this to german:
{{ now().strftime('%A') }}
@muted berry the temperature checks should be in ascending order. The way you have it now, if the temperature is 22, it'll set the fan mode to 4. I also don't see a service there but I'm guessing you just didn't include it in the paste
So you mean I should invert the entire thing?
Yeah, should be if temp < 22 ... elif temp < 23 ...
The template is evaluated from top to bottom and stops when it meets one of the tests
action:
- data:
entity_id: climate.overvaningen
fan_mode: '{% set temp1 = states(''sensor.temperature_5'')|float %} {% if (temp1
< 22 %) } 2 {% elif (temp1 < 23 %) } 3 {% elif (temp1 < 24 %) } 4 {% else
%} 2 {% endif %}'
service: climate.set_fan_mode
So, like this?
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
Also make it a multi-line template like how you had it in your original paste
Oh and this:
{% if (temp1 < 25 %) }
``` should be
{% if temp1 < 25 %}
I did that but unfortunately it returns an error
here's exactly what's in the automations file
Read my previous message
I did, and corrected the paste
There's also still no service call
sec
had to reopen the file
the formatting is completely messed up when pasting the template via the ui
Yeah, don't use the UI for templates
how should the formatting be made correctly?
Might work if you choose Edit as YAML in the overflow menu in the UI though
for the actual template part
The way you had it in the original paste, plus my corrections
"action:
- data_template:
entity_id: climate.huvudvaningen
fan_mode: >-
{% set temp1 = states('sensor.huvudplan_2')|float %}
{% if (temp1 < 22 %) } 2
{% elif (temp1 < 24 %) } 3
{% elif (temp1 < 24 %) } 4
{% else %} 2
{% endif %}"
oooh
nevermind
just saw lol
Still didn't correct this... #templates-archived message
action:
- data_template:
entity_id: climate.huvudvaningen
fan_mode: >-
{% set temp1 = states('sensor.huvudplan_2')|float %}
{% if temp1 < 22 %} 2
{% elif temp1 < 23 %} 3
{% elif temp1 < 24 %} 4
{% else %} 2
{% endif %}
there we go
Do you have a service call in there too?
yes
~share @muted berry
@muted berry Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
Please use a code share site to share the whole thing, so we don't have to play guess if the formatting is valid or guess if the construct is valid
When working with templates, don't forget:
- You can test them in Developer tools -> Templates
- Rule 1 and rule 2 (https://www.home-assistant.io/docs/automation/templating/#important-template-rules)
Did you test the template?
yes
And the fan modes are 2, 3, 4?
yes
at least the ones I want to trigger
and this is the output
action:
-
data_template:
entity_id: climate.huvudvaningen
fan_mode: >-2
from the template test
Then the template is valid
hi - I've been stuck on this one for a bit now. Trying to get the nr of hours and nr of minutes from a duration sensor (from the history_stats integration) to calculate the total nr of minutes duration. So the sensor outputs something like '6h 35m' instead of 6:35 and I would like to extract 6 and 35 to calculate 395.
{{state_attr('sensor.filtered_today_hrs','value').split(':')[1]}} would have worked if the format was 6:35 but doesn't work on '6h 35m'. Is there an elegant way fo doing this?
{% set filtered = "6h 35m" %}
{% set hours = filtered.split('h ')[0] %}
{% set min = filtered.split('h ')[1].replace('m','') %}
{{ hours|int*60 + min|int }}
@quick cape how bout this, first line is just setting the variable
@quick cape the actual state of a history stats sensor that's calculating time is a float in hours, so you could just make a template sensor with this as the value_template if you want to convert it to minutes:
"{{ states('sensor.filtered_today_hrs') | float * 60 }}"
how do i specify value template if my sensor value is between 0 to 1.94 using is_state?
currently i use this {{ 1.94 > states('sensor.genset_light_intensity_2') | float > 0 }}
but want to use is_state
You can't
using is_state as follows {{ 1.94 > is_state('sensor.genset_light_intensity_2') | float > 0 }} gives error Unknown error rendering template
Why do you want to use is_state()?
i need is-state if my anolog sensor goes uniavilable my template also goies unknown or unavailable
i read in documentation as follows
If you are using the state of a platform that takes extra time to load, the Template Binary Sensor may get an unknown state during startup. This results in error messages in your log file until that platform has completed loading. If you use is_state() function in your template, you can avoid this situation. For example, you would replace {{ states.switch.source.state == 'on' }} with this equivalent that returns true/false and never gives an unknown result: {{ is_state('switch.source', 'on') }}```
you'll be fine with what you have
what you have will return False if the entity doesn't exist or is unavailable
he can use if else statement if he really really wants to be sure ๐
or if you actually want it to display unavailable when it's unavailable i believe you can use this option: https://www.home-assistant.io/integrations/binary_sensor.template/#availability_template
I was unable to add default state or initial state to sensor also
those aren't valid options for a binary template sensor
{{ 200 > states('sensor.genset_light_intensity_2') | float > 0 }}```
i have added availabilty already
this is my full config
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
friendly_name: "Binary Lux Power Sensor"
device_class: power
value_template: >-
{{ 1.94 > states('sensor.genset_light_intensity_2') | float > 0 }}
availability_template: >-
{{ 200 > states('sensor.genset_light_intensity_2') | float > 0 }}```
i think you're fine then. if sensor.genset_light_intensity_2 is unavailable or out of the range the template sensor will be unavailable
in fact, you could test that by going to developer tools > states and changing the state of sensor.genset_light_intensity_2 to unavailable (or really any word)
Assume analog sensor is in OFF state & due to wifi issue anlog sensor goes unavailable i see this binary sensor goes unavailable Then to OFF again. Hence my automation is triggred twice
but actually its OFF & no automation to be triggered
make automation use from on to off only
make automation use from on to off only
@jagged obsidian I agree but its OFF to unavailable to OFF HA tiggers unavailable to OFF as off trigger
that shouldn't if you make the automation use
from: 'on'
to: 'off'
``` like blakadder is saying
actually its no change OFF to unavailable to OFF = OFF state only
let's see the automation
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
i'm having trouble understanding the issue you're experiencing
my automation is in nodered
and you want the automation to trigger when the sensor goes from on to off?
on to off automation 1
off to on automation 2
am ok to switch the automation to HA as well
well i don't know node red, but if it's set up to only trigger from on to off or off to on then unavailable to off shouldn't trigger (or off to unavailable)
@buoyant pine actually am using the template binary sensor to find if my home is running on genset or power line (Basically power outage monitor). wen Genset on an LED glows in my panel which the LDR reads a Anlog value am converting that anolog value into binary template sensor as ON & OFF.
When there is a power outage the binary template sensor acts this way before power outage its OFF - when power outage it becomes unavailabe (For say 5 -15 sec) - Then it changes to ON
hence OFF-unavailable ON = automation 1
Similary ON - unavailable - OFF = automation 2
but ON - unavailabe - ON or OFF - Unavailable - OFF is not poweroutage its just a wifi disconnection or esp reboot
hope it explains my problem
ah i see what you mean
Any solution possible?
Couldn't you represent the previous state in an input_boolean? Only update the input_boolean when the new state isn't 'unavailable'.
@edgy dirge make a template sensor that use's the previous state if unavailable
- platform: template
sensors:
powerline:
value_template: >
{{ states('binary_sensor.powerline') if states('binary_sensor.esp_powerline') in ['unknown','unavailable','None'] else states('binary_sensor.esp_powerline') }}
Then you want the state attributes, not the state itself.
{{ state_attr('weather.home','some_attribute_here') }}
You can see the attributes of an entity if you go to
> States and pick your entity.
got it
so like this?
- platform: template
sensors:
weather_temp:
friendly_name: "Temperature"
entity_id: weather.home
value_template: "{{ state_attr('weather.home','temperature') }}"
Looks okay. Try it out and see what the config check says
Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.
When working with templates, don't forget:
- You can test them in Developer tools -> Templates
- Rule 1 and rule 2 (https://www.home-assistant.io/docs/automation/templating/#important-template-rules)
template works there, just tring to build a sensor
ok, sensor works for humidity, but not for temp
Do you have them both defined in the same file?
yes
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
Share the config for both (and any related ones you added with them)
only difference is replacing the word temperature with humidity
And the entity definitely had an attribute for temperature? What's the sensor doing?
what's wrong with it?
You may also want to compare what you did with the examples in the docs
There are multiple ways to run it. For now, try the UI checker.
ui checker says fine
Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.
Haha, prime example of why the command line one is preferred.
sensor:
- platform: template
sensors:
solar_angle:
value_template: "{{ state_attr('sun.sun', 'elevation') }}"
sunrise:
value_template: "{{ state_attr('sun.sun', 'next_rising') }}"
``` From the docs
aha
๐
Easy once you spot it
YAML has list items (which are preceded by a hyphen) and dictionary items (which are not). Can't have a duplicate dictionary key.
i understand what happened.
I am using the OpenSprinkler integration and I made an input slider to set the runtime seconds as well as a button that calls the opensprinkler.run service. This is my code for the button : type: button tap_action: action: call-service service: opensprinkler.run service_data: entity_id: switch.s01_station_enabled run_seconds: '{{ states("input_number.runtime_zone1") | int }}' entity: switch.opensprinkler_enabled but I get this error when clicking the button Failed to call service opensprinkler/run. expected a list for dictionary value @ data['run_seconds']
Any ideas ^
?
The problem is the template still, chaotik. Test it in
> Templates
It doesn't recognise whatever it's evaluating to.
hehe.. sorry.. I thought you meant to try in the template room ๐
I see what you mean now.
Nope.
= Developer Tools
got it ๐
This channel's probably better for this conversation anyway, tbh.
so this '{{ states("input_number.runtime_zone1") | int }}' returns the right value (i.e. the integer with single quotes around it though)
if I remove the single quotes, then I get the clean integer
However, when I same it without the single quotes, it replaces the code with '[object Object]': null
In the template dev tool, you don't need quotes around it. In anything else, you do.
So your code should have run_seconds: '{{ states("input_number.runtime_zone1") | int }}'. It needs the quotes just so whatever reads the YAML knows where the template starts and ends but it'll throw them away and only evaluate {{ states("input_number.runtime_zone1") | int }} (which is your integer).
If you put a template into something without the quotes, you get that stupid object Object nonsense. Which... sounds suspiciously like a JavaScript thing to me. What card is this going in?
That's how the front end tries to represent a dictionary
right now it's just a button card. After I get it to work, I'd want it as a entity button row
How do I deduct a sensor value from 100?
A minus sign usually works well for subtraction
You've already got one that divides, you can use that as the base
states('sensor.internal_media_used') gives you the value, subtract it from 100
uhhh what would that look like?

{{ thing - other_thing }}
``` standard basic maths
Replace thing with 100 and other_thing with the relevant states()
yeah except that said unknown in the template editor
that 
I did a thing, it didn't work, why ๐คฆ
You should know by now... you need to show us the code
Much much better to tell us what you've done, what the problem is, and what your goal is than ask questions that make it sounds like you don't know basic maths ๐
template editor is broken. States shows the correct percentage but template editor says unknown:
{{ states('sensor.disk_free_percent_merged')}}
Then that entity doesn't exist
yeah it does
Please use imgur or other image sharing web sites, and share the link here.
or I guess copy-pasted wrong sensor name!
Did you copy and paste the entity from States?
no
just did, same thing
Then something weird as hell is going on with your system...
yeah its cursed I know
The platform system monitor does NOT have a disk_free percent. only disk free https://www.home-assistant.io/integrations/systemmonitor. Unless you have used your own calculations
then you do your maths of 100- disk_use_percent!. So next time, do double check before making claims of "template editor does not work" ๐
no, that was for another sensor:
sensor.network_health_1h
which I still need help with
then you do your maths of 100- disk_use_percent!. So next time, do double check before making claims of "template editor does not work" ๐
What? The issue persists, I'll reboot it at the end of the day to see if it fixes it or not
also not really a claim, I did send screenshots
you created your own sensor which has incorrect math probably. You could have just used{{ 100 - states('sensor.disk_use_percent')|int }}
that int at the end fixed the actual issue
well, it was not an issue in the first place, just your understanding of the usage ๐
well it was, to me
with that logic, everything is a non issue if everyone knows everything
The output of states is a string
This is why https://www.home-assistant.io/docs/configuration/templating/#states-examples shows the |float filter
with that logic, everything is a non issue if everyone knows everything
dunno about your logic, but if you have not read the docs or not know something, then the logic of stating something is broken is incorrect IMHO
i am trying out the crypto sensor that scraps the values.. how do I create a template that takes the value of a coin and then mutiplies it by how many coins you have in a template?
{{ x * y }} (I'll let you substitute x and y)
how do you put that into the configurations.yaml file?
cryptocurrency_name: "bitcoin"
currency_name: "aud"
update_frequency: 1
value_template: '{{ value_ }}'```
or am i missunderstanding how all this template stuff works?
Well that's not a built-in integration. Are you using a custom component?
yes
And what do the instructions say?
Forget your solution for now. What does that custom component do? Does it create sensors for you? Is it just a UI thing?
it creates sensors for you
You'd need to make a template sensor that multiplies number of coins by the unit price
So use those sensors and create a custom sensor wrapping it.
You can more or less copy the first example and change the template and names.
ahh ok.. let me give that a try.. that's the part of understanding i was missing
You can't just add whatever you like to an integration. They all have a pre-defined set of values they'll accept. Start with what you know, don't just guess ๐
Colonal Klink said it best: "I KNOW NOTTHING!"
would this be correct?: - platform: template sensors: friendly_name: "Bitcoin Owned" unit_of_measurement: '$' value_template: '{{ value_sensor.cryptoinfo_bitcoin_aud * 0.1234 }}'
You haven't given it a name
Pay attention to the nesting of the example:
sensor:
- platform: template
sensors:
solar_angle:
friendly_name: "Sun angle"
unit_of_measurement: 'degrees'
value_template: "{{ state_attr('sun.sun', 'elevation') }}"
solar_angle is the name of the sensor, 'Sun angle' is the friendly name. You must provide the first, the second is optional.
like this? - platform: template sensors: crypto_bitcoin_owned: friendly_name: "Bitcoin Owned" unit_of_measurement: '$' value_template: '{{ value_sensor.cryptoinfo_bitcoin_aud * 0.1234 }}'
ok ta
Nee bosh
im confused on calling a service with a template. the template I have created below does return the string "fireworks" but for some reason its not interacting withe the wled client.
entity_id: light.wled_2
intensity: 100
speed: 10
effect: >
{{state_attr('calendar.holidays_for_lights' , 'message')}}
when i call service "effect.wled" with the template removed and the string "fireworks" it properly communicates with the wled integration
value_sensor.cryptoinfo_bitcoin_aud is a string @vapid pumice - states('value_sensor.cryptoinfo_bitcoin_aud') is the state of that entity
states('value_sensor.cryptoinfo_bitcoin_aud')|float would be a number you could use
@thin furnace Helps if you share the whole thing, so we can tell what you've overlooked - like Rule #1 or Rule #2 (see the topic)
@arctic sorrel cheers.. I was just trying to figure that out.. but I get 0.0 now instead of unknown
Well, test it all out ๐
value_template: "{{ states('value_sensor.cryptoinfo_bitcoin_aud')|float * 0.1234 }}"
unknown
if I remove "value_" i get the value

now how do i round it to 2 decimal places
| round(2) but you need to put what you currently have in parentheses otherwise you'll only round the 0.1234
ok i'll give it a go
@arctic sorrel maybe this is the wrong channel since i know the template works as the template returns the correct string in the developer/templating tab. I am only working in the call service tab currently, I dont see what else I can share a this point.
How about the whole automation/script/whatever?
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
ill create a script and share it
yes
That, by itself, won't do anything
sorry my son distracted me
It needs to be in a service_data block (see Rule #2)
@arctic sorrel for some reason when i was playing around wiht this last night i went down that road and kept getting errors, i guess it was too late for me. got it working now was soo simple.
thanks again
first time with templating and service calls.... obviously lol
Hallo all
I've a probably small question where I need your help:
I created a template sensor that returns a value between 0 and 1
Now I want to use this value in another sensor, but set this sensor as a value will just return 0
{% set f = state_attr('sensor.light_factor', 'value') | float %}
{{ f }}
also tried following with no luck
{% set f = states('sensor.light_factor')| float %}
can you help please?
Does sensor.light_factor exist?
yes {{ states('sensor.light_factor') }} returns the value
return "value: 0.21594674897802127"
What do both templates you've tried show at developer tools > template?
sensor.light_brightness value: 20.0 f: 0.0
v: value:
0.21594674897802127
x: None
friendly_name: Lichthelligkeit
sensor.light_factor value: 0.21594674897802127 friendly_name: Tageslicht Faktor
x: >-
{{ state_attr('sensor.light_factor', 'value') }}
Just put
{{ states('sensor.light_factor') }}
{% set f = states('sensor.light_factor')| float %}
{{ f }}
f is still 0.0
Let's see a screenshot of developer tools > template with what I showed you in it
Please use imgur or other image sharing web sites, and share the link here.
Not at all what I asked to see
? both commands are attributes of light_brightness
Or did I got you wrong?
wait now I might have understood
Yeah, remove value: from under value_template: in the template sensor config
That's making the state of that sensor start with value: which is not what you want
It WORKS!!! I would never have found this! Thank you so much!
No prob, but I'm wondering where you got the idea to put value: there too
Just wondering if something was misleading in the documentation
kinda from
data_template:
message: >
but somehow I must have misread there something.
Oh gotcha. In an automation, data_template: replaces data: when one of the other pieces of service data (message: for example) contains a template
Looking for some guidance how to extract forecast from a weather sensor
The attributes look like this:
- datetime: '2020-06-14T00:00:00'
temperature: 21.1
templow: 9.1
condition: partlycloudy```
How can I get the forecast --> condition string?
When you say a weather sensor, do you mean the device or an actual sensor in HA?
an actual sensor - weather.smartweather
it's a HACS integration with my weather station + dark sky forecast
Then you get an attribute from a sensor something like this: {{ state_attr('domain.entity', 'attribute_name') }}
In your case, you're probably interested in something like weather.home and condition.
My problem is that there are multiple entries for the next 5 days, marked with a timestamp - datetime: '2020-06-14T00:00:00'
I need to pick the one for the next day, something like now().day +1 if that is possible at all
and match it to the datetime entry, then pick conditions from there...
That's not what you suggested in the snippet you posted...
If you want help, be clear about your requirements.
Show the real snippet please.
So I'm trying to add this template to my configuration.yaml but it fails. I'm guessing I've screwed up something in the formatting
yeah, you can't do that
you want something more like this:
# {% if states('sensor.occupancy')|int > 10 %} green;
# {% else %} red;
# {% endif %}
you're using is_state() and trying to put a different test in the arugment
it's not a YAML formatting problem, it's a jinja issue
so how would I properly write this? the script isn't mine
you also have nothing in the else clause, or an {% endif %}
it looks like you copied part of a broken template ๐
It's actually the entire template that a friendly dude sent me
What I'm trying to achieve is having an automation read the temp of a specific template and once the temp hits a few key values, I want the fan speed of my hvac to change accordingly
{% if states('sensor.temperature_5') < 25 %}
4
{% elif states('sensor.temperature_5') < 24 %}
3
{% elif states('sensor.temperature_5') < 23 %}
2
{% else %}
something
{% endif %}
see the difference?
"Configuration invalid
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['sensors']['flaktlageovervaning']['value_template']. Got "{% if states('sensor.temperature_5') < 25) %} 4 {% elif states('sensor.temperature_5') < 24) %} 3 {% elif states('sensor.temperature_5') < 23) %} 2 {% else %} 2 {% endif %}". (See ?, line ?). "
that's from pasting the edit in my config.yaml
I literally copy pasted what you wrote with the addition of changing something into "2".
do it again
here's what's currently in my config.
I can see from your error that you don't have exactly what I have above
holy..it works wtf?
that's the goal, right?
I ment the config check
that, too
Now I need to test the template ๐
now, read it and understand it. and how it's different from your first attempt
so I assume that the action is call_service in the automation?
I sure will man..thanks a bunch!
depends on what you want to do with the sensor that you defined
this - action:
- service: climate.set_fan_mode
data:
entity_id: climate.overvaningen
fan_mode: '{{ states.sensor.flaktlageovervaning.state }}'
basically call the template to compare current temp of the sensor to the template and set fan mode thereafter
that's overcomplicating things
is it?
I've tried everything else by now without success
Heck..if you can help me solve this, you've got a beer on me
the hvac has four fan modes
3*
from 2-4
And I want the hvac to adjust the fan mode based on the temp of an aqara sensor
unless you're using that sensor somewhere else, it's weird to create a sensor for the template and then use the sensor value in the action
just put the template in the action
Okay? so just straight as an action?
it'll work, but it's just kinda roundabout
action:
- service: climate.set_fan_mode
data_template:
entity_id: climate.overvaningen
fan_mode: >-
{% if states('sensor.temperature_5') < 25) %}
4
{% elif states('sensor.temperature_5') < 24) %}
3
{% elif states('sensor.temperature_5') < 23) %}
2
{% else %}
1
{% endif %}
actually, that. action: isn't a list element
make sense? did you have another reason for wanting the sensor?
here's what I had earlier that failed
yeah, that does make sense..a lot more sense than defining a sensor for a single use
hey, that's better
it is, but it fails
your indentation is wrong
Why am I not surprised
action:
- data_template:
entity_id: climate.huvudvaningen
fan_mode: >-
{% set temp1 = states('sensor.huvudplan_2')|float %}
{% if temp1 < 22 %} 2
{% elif temp1 < 23 %} 3
{% elif temp1 < 24 %} 4
{% else %} 2
{% endif %}
service: climate.set_fan_mode
service: climate.set_fan_mode should be 2 spaces to the left
mind posting the entire thing in a hastebin? I'll 100% get it wrong lol
the spacing was even more messed up in hastebin, but looked better when I copied and pasted into VSCode
correct? https://hastebin.com/ewabulalow.bash
uh, no
your action: block was way over to the right
trigger:, condition:, and action: need to be lined up
- id: needs to move left two spaces (paste error maybe)
really, everything else needs to move 2 spaces to the right
here's a correctly formatted automation:
# turn off the fan after an hour
- id: Whole house fan turn off after time
alias: Whole house fan turn off after time
initial_state: true
trigger:
- platform: state
entity_id: switch.whole_house_fan
to: 'on'
for:
hours: 1
condition: []
action:
- data:
entity_id: switch.whole_house_fan
service: switch.turn_off
the ui really screws things over
it's still wrong
Move service: climate.set_fan_mode left two spaces
And then the entire action over two spaces heh
yeah, that won't work
I did
and yet
there's a ton of spaces in that pastebin
alright, I'll put everything to the left side
what editor are you using?
I encourage you to look into VSCode, which makes the indentation much easier
YES!
