#templates-archived
1 messages Β· Page 109 of 1
ah @coarse tiger @charred dagger setting the right chmod on id_rsa fixed it, I was testing as non root and it worked but when testing as root it complained that it had to many permissions chmod 600 id_rsa
TIL. Thanks for reporting back
++
@pure pulsar FYI there's no karma on this server if that's what you were trying to do
I just figured they were trying to wake thomasloven up
Not sure where to post this but figured this might be the best place. When I switch my LG TV off via the frontend it turns off immediately but takes a while for the icon to update on my frontend. Is there a way around this by making some kind of template that shows off it's toggled off
state seems to be delayed too
then not much that you can do
is there any way to say if I turn the TV on via the template switch, it shows on for a few seconds until it can check if the TV is on and vice versa for when it turns off?
sure. you define the state value
use an input_boolean or something
you probably can't make the TV or the integration respond faster, but you can just maintain your own "optimistic" state
or just leave the value off entirely, and it will just assume
Yeah, the reason for the delay is because that integration is polling, not push
Home assistant might ask for the state right away after changing it, but if that's the case the TV must not report an updated state when that happens so it doesn't get updated until the next polling interval
If I left the value_template out of the template switch, it would only show on or off if toggled or you say it would assume..what..based on what?
as in the docs:
value_template template (optional, default: optimistic)
Defines a template to set the state of the switch. If not defined, the switch will optimistically assume all commands are successful.
I'd say you just leave it as is and deal with the delay
Home assistant might ask for the state right away after changing it, but if that's the case the TV must not report an updated state when that happens so it doesn't get updated until the next polling interval
@buoyant pine thanks for the explanation. It really is such a minimal delay but it's the little things that if I have the power to tweak, great, if not, then I guess I can live with it π
that's probably the best option, aside from an overly complex setup which will probably not work 100% as intended
I imagine I could set its value_template to an input boolean, which is managed by automations polling the state of the TV
so if I set the switch to off, it will set the input boolean to off, and an automation would turn the TV off based on the state change of the input boolean
then if I set the switch on, the TV will turn on and automation watching for state changes to the mediaplayer can set the input boolean to on...
do you think that kind of makes sense?
probably not worth it at all mind you
sure
haha, maybe I'll leave it - I feel like too many things you don't expect to go wrong can go wrong when you overcomplicate things
thanks both for being sounding boards though π
Howdy
a simple question it' possible de define a severity value lovelace Gauge from an input number ?
The gauge card doesn't care that it's an input_number. Your question is about the gauge card, you're better off asking in #frontend-archived
Hey, does anyone see what's wrong here? Just checking if a device is offline
binary_sensor:
- platform: template
sensors:
LR_unavailable:
value_template: >-
{{ is_state('light.yeelight_2','unavailable') }}
(getting an error)
Please don't say I have an error or describe an error. Share the whole actual error message so we can help you.
100% probability it's the slug π
If we can spot that without the error, just think how much easier it'd be with the error message to help us
Yeah, good point. The error is about formatting I suppose, but I have some hard time trying to copy text from console after I read your msg.
π€·
Use a proper SSH client and you'll be able to copy and paste more easily π
Regardless the error message should tell you what the solution is, something like (try lr_unavailable)
OK maybe I just don't understand the terminology.
It tells me about invalid slug, and so do you
I have no idea what it is xD
Heh...it's the thing in the fourth line in what you posted
daaaaaamn
See the link Tinkerer posted above
Thanks!
No caps in entity IDs (and the slug determines the entity ID)
The error message also is telling you what to use instead
Hmm, you're right. I was focusing too much on technical output and missed that
Something something forest, something something trees.
Canβt see the something something through the something something
|| something something π€ something something ||
|Docker|
Yes
Aw crap. Forget it
|| text ||
Yea...that
|| π€ ||
I'm failing on the syntax for making a template sensor that parses a json object and gets one value out... it's a small json object read from a file sensor already and I just want to put the json values into separate sensors.
I get the states of the entity and I to_json it but testing the template in devtools trying to access the values inside gives me no output. But printing the whole json object out as json works fine
AH got it {{ (states('sensor.XXX') | from_json).name }} that wasn't so hard π
Hmm, but just because it works in devtools, doesn't mean it works in the configuration file. π¦
I'm so confused... why couldn't I write this {{ (states('sensor.XXX') | from_json).name }} in a value_template on a template sensor?
It works just fine in the devtools template editor
5 Rules for better support:
- Be very specific about the issue/problem you are facing (a problem clearly stated is a problem half solved)
- Absolutely NO negative comments about individuals, developers or the community
- Read the documentation (RTFM). It is an open source product, you are allowed to contribute, but not whine
- Every setup is unique in its own way. Share your config, code, logs and other relevant info via https://hasteb.in/ or https://paste.ubuntu.com/ - don't post walls of text in the channels
- Keep the channel live by being friendly, offer help where you can, learn when you can't!
- Remember to review #rules
We are thankful to all the members who dedicate their personal time helping others.
ok, that worked π
Hi guys :)
hi, does anyone know how to narrow down this further? the result is too big
curl -X GET http://192.168.40.210:61208/api/3/processlist/name/rpi-temperature
For isntance i want it to show the status in the api
The result is too big for the rest api, must narrow it down .
Where? A command line sensor?
If so, you can use value_template. That parses json
oh... the solution was to not do a one liner.... the syntax was correct but i had to split it apart like so: value_template: >- {% set value = states('sensor.host_network_control') | from_json %}
{{ value.tunnel }}
Where? A command line sensor?
@charred dagger yes command line sesnor π and i have 5 rpi-temperature running :/
@thorny snow {{ (states('sensor.host_network_control') | from_json).tunnel }} should work then.
@thorny snow
{{ (states('sensor.host_network_control') | from_json).tunnel }}should work then.
@charred dagger I agree, that's what made me confused... when I checked the config it gave me an error.
@charred dagger
sensor test:
- platform: command_line
name: Used mem
command: "/usr/bin/curl curl -X GET http://192.168.40.210:61208/api/3/processlist/name/rpi-temperature"
value_template: '{{ value_json["rpi-temperature"][0][["status"]] }}'
output of the curl: https://paste.ubuntu.com/p/wqy3bPynvt/
π
what should i do π³
sorry ignore the name i was testing ( used mem) its irrelevant
Its all good i did it π
how can i change the color if my state is "S" in customize for my dashboard
sensor.rpi_milksensor_script_process_1:
icon: mdi:application
icon_color:
templates: if (state === 'S') return 'rgb(67,167,47)'; else return 'rgb(219,27,8)';
whats my problem here π¦ ?
need to use actual template syntax
Jinja is used by Home Assistant's template engine, see the Jinja Template Designer Documentation
https://www.home-assistant.io/docs/automation/templating/
https://www.home-assistant.io/docs/configuration/templating/
@fossil hearth you need to wrap it in quotes. or use multiline notation. Also, that code requires that CustomUI is installed.
sensor.rpi_milksensor_script_process_1:
icon: mdi:application
icon_color:
templates: >
return (state === 'S') ? 'rgb(67,167,47)' : 'rgb(219,27,8)';
@dreamy sinew thats CustomUI js templating
ah
yeah, it's a thing of the past
but some peeps still use it
problem is, beginners don't know the difference
mods too apparently π
Na, I mean, beginners search the forums for "change color based on state" and they find all the CustomUI templates and think it will work
i definitely recognized it as JS but thought it was just standard bad syntax errors
i think i asked this before, but is there a way to "wrap" a configuration entity in a device, so that it can be assigned to an Area?
no
so there is absolutely no way to put orphan entities in a room.
That's a great idea. Put them in the basement where orphans belong.
No, only Devicesβ’οΈ can be assigned to areas
Even then, areas still aren't particularly useful
would you suggest a group object instead? oh wait, groups can't be added to areas either
i suppose it's down to custotmizing the front end then
Areas affect the auto generated layout and can be used with most services that take a list of entities, so they're definitely useful.
Ah, didn't realize that about the auto-generated layout
(yeah, i'm still using the default automated layout. Room A has lights 1,2,3, but the "Lights" group is 20 miles down the page for entities that belong to Room A as well)
There's always groups. I believe they take priority over areas.
Do groups appear as lovelace cards like areas do?
As in do multiple entities appear together in a single card? Yes
I have a group with most of my lights in (so I can turn that group off in one go) and they appear together.
ok. That works then π
how can I build a list starting from a string with value separed by / ?
{{"foo/bar".split("/")}}
What does your template output?
What does states('sensor.vento_tosko')[1] output?
[1] give ''
' '
I was planning to ask [3] to extract the thirs, but i neeed to convert into a list. isn't it?
Ok... let's step right back... what's the full output of that sensor's state?
the full output, retrieved with PPRINT() is
'\n 3.2\r\n Km/h - WNW\r\n\n'
so I want to extract the WNW
Without pretty print. Without any templating or functions. Just the value of states('sensor.vento_tosko')
4.8 Km/h - WNW
Try {{ states('sensor.vento_tosko').split(' - ')[1] }}
it is '34 / doen / yeep / poke / wsw'
i need t extract the third element
So all of this was bad information. That doesn't help us help you.
Start with facts π
hi, to provide an additional layer of security, I would like to add a security token (for instance a hash of the current date and a shared key) to the body of an MQTT payload that I publish to the broker via an automation. What would be the best approach to do this (generate the token and dynamically add it to the payload)?
how do you want to verify the token?
Verification is done on the receiving end via a python script
so then you can just create a token with templating and save it to a file with e.g. https://www.home-assistant.io/integrations/file/#notifications in the automation.
you can then either read that with your python script or place it in /www? does that solve your problem?
Hmmm, how would I go about creating the token through templating? Should I use a custom filter for that? Or can I just use python code in Jinja? (Encryption libraries)
I think you're limited to what's available in Jinja 2 and whatever native stuff Python can do with basic data types (strings, lists, tuples, etc).
But this all begs the question: why? If your MQTT isn't public, it's already secure.
Yeah, I might be overthinking it... :)
I'm gonna check out templating just for the fun of it, if it takes too long, I'll do it without
okay so how does one take a test template from the one in developer tools and apply it? Where does it go?
that kind of depends on the template π
well, if you describe what you are trying to achieve and share your template it's more likely to get your question answered
its a long story you ready?
well, shoot. but try to stay on the path
okay so i have a thermostat through MQTT and it sends its data thru the climate entity/intergration.. in Celsius.. I am from the states and would like to view it in Fahrenheit. change the unit of measurement doesnt work it doesnt convert the data.. I went into the template tool and wrote something in to do it ... it works but now I dont know what to do with it.
Sounds like you want a template sensor
well thats what i tought too but config keeps yelling at me saying nope
The one command the bot doesn't understand π€£
Ehh, it should be .template but that's taken by another command and I keep forgetting
So...let's see the config @weary garnet
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
oh boy i will try this but it tends to not work as I am beind PIhole
If it's under 15 lines you can post it here
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/.
- platform: template
sensors:
set_temperature:
entity_id: climate.bathroomfloor
friendly_name: Set Temperature
unit_of_measurement: 'F'
value_template: '{{ (((states.climate.bathroomfloor.attributes.temperature) * 9 / 5) + 32) | round(1) }}'
Invalid config for [sensor.template]: expected dictionary for dictionary value @ data['sensors']. Got None
extra keys not allowed @ data['set_temperature']. Got OrderedDict([('entity_id', 'climate.bathroomfloor'), ('friendly_name', 'Set Temperature'), ('unit_of_measurement', 'F'), ('value_template', '{{ (((states.climate.bathroomfloor.attributes.temperature) * 9 / 5) + 32) | round(1) }}')]). (See ?, line ?).
Indentation issue
Note the indentation here: https://www.home-assistant.io/integrations/template/#configuration
show me please
Particularly under sensors:
and ya know in the yaml checker it checks off fine
In the future please follow this when sharing code here instead of pastebin, otherwise it's really hard to see the indentation: #templates-archived message
What YAML checker?
when you go to edit any yaml
?
Ah, I don't have add-ons so I didn't know what you were talking about
Yeah, don't trust that heh
okay so yea that checked out..
for each value i want converted it needs its own template entry yes?
Yeah
ill let you know how it goes...
I left to get a coffee and some popcorn. When I come back there's no story left. This forum is too efficient.
Right, masters of templating. I have a little flask app, delivering some content to a local host from a csv that changes. I've got restful sensor, and if I go to template editor with {{states('sensor.cinema_paradiso')}} I get https://hastebin.com/bagufisemu.json What I'm trying to get to is the text that would fill 'Fairy Tale: A Trust story' (a few others, but that'll probably be enough tog et me started) Tried a few things and cannot make it work
I have tried multiple options, I am a failure π
{{ states('sensor.cinema_paradiso').data.Name['0'] }} should do it
If that last key hadn't been a number, you could've done it without the weird square bracket notation like this: {{ states('sensor.cinema_paradiso').data.Name.one }}. Keys starting with numbers don't play nicely with templates.
I am getting UndefinedError: 'str object' has no attribute 'data' For what it's worth, the haste in automatically read as json, in theory the flask app should be returning json (jsonify) but who knows.
You need to first convert the state value to a json :
{{ (states('sensor.cinema_paradiso') | from_json).data.Name['0'] }}
Winner winner!
Thank you. I've been trying to work out how to feed stuff from my Python stuff into HA, and thought I'd have to create a whole integration - this is definitely the better option
I should've realised that it wouldn't auto-cast the string to an object. I hope the rest makes sense to you π
Yeah, I wasn't far off of it, and all the language is basically python string manipulation familiar enough that it makes sense π
Yes. The templates in HA use a mix of Python and Jinja 2 stuff.
Yeah it's not perfect, but it's close enough π
I am trying to figure out this automation, but it doesnt work. Can someone see whats wrong?
alias: Ny automasjon
description: ''
trigger:
- platform: template
value_template: ' {% if (''states.sensor.nordpool_kwh_oslo_nok_3_10_025'') > (''states.sensor.off_peak1_sensor'') %}{% endif %}'
condition: []
action: - service: switch.turn_on
data: {}
entity_id: switch.telldus_tzwp_102_plug_in_switch_switch
mode: single
Not without more info on what youβre trying to do and what isnβt working
Your template is pretty broken, though
Syntax is all wrong
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)
Works fine in developer tools, i am trying to run a automation when the electricity price exceeds off peak
Just do "{{ states('sensor.whatever') | float > states('sensor.whatever2') | float }}"
Thank you @buoyant pine ! π I get true and false in dev tools, but it will still not trigger the automation. Im pretty new to templates
To test an automation there's three stages you can follow. Testing the action, the condition and action, and the whole automation:
- Use Developer tools (
)-> States to find the automation, click
and then push Execute. If this fails your problem is in the action:section, and details should be found in your log file - Use Developer tools -> Services and call
automation.triggeron the automation withskip_condition: false. If the first passes but this fails then the problem is in yourcondition:block - Use Developer tools -> States to find the trigger entity, click the name, then change the state (at the top) to something that'll trigger the automation before pushing Set State. If this fails then the problem is with your
trigger:section.
If they all work, and your automation didn't run, it's probably turned off.
is there any way to see logged in user as template? {{ hass.user }} or something ?
@azure tinsel I saw this yesterday: https://www.home-assistant.io/lovelace/markdown/#template-variables. For that card there is a {{user}}, though I am not sure if that is the use case you are interested in.
i does not work on template.. but ill try, thank you
yeah.. it does work on that markdown card
sadly i wanted to use it on another card but maybe it is not available π
Is there a way to reuse parts of yaml in a template sensor? I have the following template that works, but uses a lot of repeating characters. Here is a just one component of it:
{{ state_attr('sensor.radarr_disk_space', 'X:\\')[0:state_attr('sensor.radarr_disk_space', 'X:\\').find("/")] | float + state_attr('sensor.radarr_disk_space', 'Y:\\')[0:state_attr('sensor.radarr_disk_space', 'Y:\\').find("/")] | float }}
you can shorten if if you define the repeating characters {% set repeat = whatyouwantrepeated %}
then just use repeat in your template
Like this:
{% set repeat1 = state_attr('sensor.radarr_disk_space', 'X:\\') %}
{% set repeat1 = state_attr('sensor.radarr_disk_space', 'Y:\\') %}
{{ repeat1[0:repeat1.find("/")] | float + repeat2[0:repeat2.find("/")] | float }}
that second line should be repeat2
Oh yea, oops, that's my bad. Meant to change that. But other than that, is it the correct idea?
ya
I would like to round a value to 2 decimals so far i have this which does work but doesnt round the number any thoughts?
{{ states('sensor.meterstand_kwh_hoog') | round(2) - states('input_number.stroomverbruik_hoog_per_maand') | round(2) }}
try {{ (states('sensor.meterstand_kwh_hoog') - states('input_number.stroomverbruik_hoog_per_maand')) | round(2) }}
that will give this error TypeError: unsupported operand type(s) for -: 'str' and 'str'
{{ (states('sensor.meterstand_kwh_hoog') | float- states('input_number.stroomverbruik_hoog_per_maand') | float) | round(2) }}
should float not int
Hi All,
Hope this is the right channel.
Quick question with the Alarm Panel i see it only allows for certain states to be used such as armed, disarmed, armed_night etc. is there a way in the config to tell it that sleep is armed_night or do I need to modify these values before they are processed by HA ?
that last one worked thanks
@grim flicker your states were strings which is why the | float was needed
iΒ΄m just starting to use templates so i have allot to learn
so now i want to calculate what the usage costs are so i want to do the value *0.22 and want to round it to 2 decimals
i have tried a few options but they dont round
{{ (states('sensor.meterstand_kwh_hoog') | float - states('input_number.stroomverbruik_hoog_per_maand') | float) * 0.22 | round(3) }}
this doesnt round
what are you trying to multiply 0.22, just the input_number?
this examples rounds {{ ( states('sensor.washing_machine_voltage') | float - states('sensor.washing_machine_voltage') | float ) | round(0) }}
oh he wrapped the sensor and input_number, needs to wrap the * 0.22 as well
it's a separate equation
sometimes it's easier to set it up like this. makes the actual math simpler:
value_template: >-
{% set t1 = (states('sensor.burner1') | float ) %}
{% set t2 = (states('sensor.burner2') | float ) %}
{% set t3 = (states('sensor.burner3') | float ) %}
# And then the actual math, not your case below
{{ ((t2-t1)/(t3-t1) * 100) | round(2) }}
thank you i will try this. What does | float do
Converts the value to a floating point number
Jinja Template Designer Documentation
For more examples and samples, visit see this page
@waxen rune i have this code but it doesnt output anything. do you have any ideas why? https://hastebin.com/iyukiyifob.yaml
when i copy the template part in the developers section to test it. the value is coming out. so it must be the rest of the code that isnt working
has sensor.meterstand_kwh_hoog changed state
yes it changes every 10 seconds its loaded out of my meter
Is the automation enabled?
change it to value
how can i get min value ot temperature from sensor for today?
with statistics i can get for last X hours, but i want only for today, for example if its 00:05 now and i have only one measure on sensor.temperature - this to be min
this one need two sensors
and will give you min from them
but will not give you min value for today from one sensor
this one only compare two sensors
Ah right
something like history stats
i use history stats to counting running time for today, and it is OK, it resets at 00:00
It was the first thing I thought of, but I realized I haven't looked at the docs for it lol
but statistics platform does not
@azure tinsel you can use the SQL integration but you need to build the lookup yourself.
yeah.. but i need to switch everything to mysql? or i can use that with the default sqlite database ?
yeah you'd probably need to swap over
thanks
@grim flicker Sorry, old example code. Good to see you solved it!
@mighty ledge it maybe can be done with sqlite too, thanks for the hint
Yeah I don't know how sqlite works with multiple fingers in the pot
sqlite> select min(state) from states where entity_id = "sensor.bedroom_temperature" and created > date('now');
18.8
looks OK
i will only query it
if it crash something ill migrate to mysql π
Hi everyone. I have retrieved a date with a scrape sensor from a website which is showing in HA in this format: 07/11/2020 - 16:45
is there any way to transform this format to something readable by HA so I can use this date in automations?
date will alwats be in the future
like 20/11/2020 - 16:45
always*
i have 2 things set up in templates , but how do i integrate them into cards ?
{{ (states('sensor.speedtest_download') | float * 1) | round(0) }}
{{ (states('sensor.speedtest_upload') | float * 1) | round(0) }}
and afval_vandaag:
friendly_name: 'Afval Vandaag'
value_template: >-
{% if states('sensor.areareiniging_gft') != None and as_timestamp(states('sensor.date')) == as_timestamp(states('sensor.areareiniging_gft')) %}
Gft
{% elif states('sensor.areareiniging_pmd') != None and as_timestamp(states('sensor.date')) == as_timestamp(states('sensor.areareiniging_pmd')) %}
Plastic
{% elif states('sensor.areareiniging_restafval') != None and as_timestamp(states('sensor.date')) == as_timestamp(states('sensor.areareiniging_restafval')) %}
Restafval
{% else %}
None
{% endif %}
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/.
@north locust what is the problem, does the templates work already?
@wraith shell I am sure there is a much better way, but I did this when I needed what you're after.
Basically it breaks down the data into a list of separate characters and then put them together again and as a last step format as time stamp.
Maybe worth a try? Just note it will only work as long as your indata always have the same number of characters.
{% set t = states('sensor.yoursensor') %}
{% set t = t | list %}
{% set day = t[0]+t[1] %}
{% set month = t[3]+t[4] %}
{% set year = t[6]+t[7]+t[8]+t[9] %}
{% set hour = t[13]+t[14] %}
{% set min = t[16]+t[17] %}
{{ as_timestamp(year + month + day + " " + hour + min ) | timestamp_local }}
Output in my case: 2020-11-07 16:45:00
@waxen rune In the developer template it outputs fine , but adding it in my congiguration.yaml gives problems ...
do you want the template directly in the card or do you create a template sensor?
afval_vandaag:
friendly_name: 'Afval Vandaag'
value_template: >-
{% if states('sensor.areareiniging_gft') != None and as_timestamp(states('sensor.date')) == as_timestamp(
Gft
{% elif states('sensor.areareiniging_pmd') != None and as_timestamp(states('sensor.date')) == as_timestam
Plastic
{% elif states('sensor.areareiniging_restafval') != None and as_timestamp(states('sensor.date')) == as_ti
Restafval
{% else %}
None
{% endif %}
please use the backticks
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/.
this one doesnt need to be in a card
so much easier to read
want to make an automation with it
but everytime i add it in my config.yaml , log spits out errors
it seems cut off, can you please share the complete code? from sensor:
ok, have you tried out each value and condition separately in dev tools so you know they work as intended?
line 27 is cut off
ok, have you tried out each value and condition separately in dev tools so you know they work as intended?
the state None is unusual, maybe should have quotation marks? but as long as it works in dev tools, it should work.
None is a keyword in Python, it should be valid in that context.
what was the solution?
Is there any way to create a state template for a history stats sensor
For example:
- platform: history_stats
name: Current Game History
entity_id: sensor.xbox_online
value_template: '{{ states.sensor.xbox_online.state }}'
type: time
start: '{{ now().replace(day=1).replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
so it dynamically shows me how much I've played the specific game I'm playing at that moment
does it display what game your playing?
the config doesn't accept the template
so the sensor.xbox_online shows what game I'm currently playing
let's saying it's "Assassin's Creed" currently
That's because you can't just make things up and expect them to work. The docs don't say it takes a template for the value. π
then I would want the sensor to essentially show:
- platform: history_stats
name: Current Game History
entity_id: sensor.xbox_online
state: 'Assassin's Creed'
type: time
start: '{{ now().replace(day=1).replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
It tracks a single state. Make a sensor for each state you want to track.
That's because you can't just make things up and expect them to work. The docs don't say it takes a template for the value. π
@ivory delta haha yeah, I realise that - just wondering if there were any work arounds
Yes... make more sensors.
Defeats the point of the dynamic nature of the sensor, but I get your point. It's not possible.
Well the sensor isn't designed to be dynamic, you just want it to be. You could probably get clever using Grafana+Influx if you record the data for sensor.xbox_online there.
Yeah, that's a shame. I'll have a look into Grafana, etc.
You could always log a feature request on the forums for something that does what you're after. Or even make something if you have the skills - HA is open source.
can I wrap an or combined with a and {{ is_state('calendar.school_year', 'on') and (states.calendar.school_year.attributes.message | regex_search('break', ignorecase=true) or states.calendar.school_year.attributes.message | regex_search('holiday', ignorecase=true)) == true }}
template editor seems to be fine with it
Yes, combining boolean logic is valid syntax.
thx
Hello folks,
Have a small question, may be someone can bring some lite for me.
Is it possible to pass variable in template states request ?
`- condition: template
value_template: "{{ states.sensor.VARIABLE.state == 'ON' }}"
- condition: template
value_template: "{{ states(sensor.VARIABLE) == 'ON' }}"`
there's no global variables, so you would have to define it elsewhere, an input_* usually is what people do
The case here is to have single script which will be ran with passed variable and do the work based on these vars..
This appears to be in a script/automation, so you can use variables.
That's how to re-use variables within a script.
And this is how to pass them in: https://www.home-assistant.io/integrations/script/#passing-variables-to-scripts
Yep, I saw and read these docs, the main problem here is to use variables inside template in states request. I believe if I pass it as in code block above, it will not be taken as variable.
IIRC you have to get clever with how you build the states('sensor.sensor_name') part of the template.
What do you want to pass in as a variable?
different sensors.. for example sensor.sensor1 , sensor.sensor2 , sensor.sensor3 etc..
How are you choosing what to pass in? Could you pass in the whole name (i.e. 'sensor.sensor1')?
Or are you only passing in 'sensor1'?
Yes, actually I can pass 'sensor.sensor1' in variable.
Will it work in the way states('VARIABLE_value') ?
Close
If you're passing in the full string as the variable 'name', you should just be able to do "{{ states(name) == 'ON' }}"
You only quote strings. If you're using a variable, skip the quotes.
I will try it, thank you! Sry if the question was stupid, I am newbie in HA. π
It's not stupid at all. One other thing... 'ON' is probably wrong. States are normally 'on'/'off'.
Yep, everything is case sensitive
And you can test your templates using something like this (just change your sensor name, that's one of mine):
{% set name = 'binary_sensor.front_door_contact' %}
{{ states(name) == 'on' }}```
ON is working in my case, it is came from my other device Megad2561 via mqtt
(in
> Templates )
Yep, everything is case sensitive
@buoyant pine Unless you do|loweron everything π
I already understood that it is case sensitive and had some problem when saw 'On' in mqtt and it cannot be changed...
Resolved by: state_template: "{{ value_json.state|regex_replace(find='OFF', replace='off', ignorecase=False)|regex_replace(find='ON', replace='on', ignorecase=False) }}"
π
Oof... that's a long way to force lower case.
Unless you do |lower on everything
Didn't know about it on those moment .. )
Heh, yeah | lower is the way to go
Here's your built in filters for Jinja 3: https://jinja.palletsprojects.com/en/3.0.x/templates/#list-of-builtin-filters
Don't use the lower() syntax, use the pipes (|lower).
Saving this link right now )
Tediore - could you pin that link?
No
Thanks guys! π
I've got a zwave sensor that spits out 22 or 23. I want to template it so it's more of a nice readable Open/Closed... but somehow I'm messing that simple process up. CAn anyone take a look at this and tell me what I'm doing wrong?
I've put it in my 'sensor:' section
{{ 'open' if is_state('sensor.guest_room_door_access_control', '22') else 'closed' }}
And remember things are case-sensitive. 'Closed' isn't the same as 'closed' for states.
Why would it matter here? aren't I just basically saying use the name Closed as output?
couldn't I call it anything I wanted?
For a sensor.
Follow conventions so they're predictable when you use them elsewhere.
If it was for the UI, you could call it what you want.
perhaps the UI is what I want...
But Lovelace won't know how to interpret 'Open'/'Closed' because they're not the right values for the state of an opening.
i guess i wasn't aware there was a difference
and for a door sensor you might want to use a binary_sensor like this:
entredorr_tmpl:
friendly_name: 'EntrΓ©dΓΆrr'
device_class: door
value_template: "{{ is_state('binary_sensor.entredorr', 'on') }}"
If it's a templates binary sensor you can use device class
I thought about using a binary sensor, but when i looked at the doc, it looked like it was looking for certain values.. 22/23 was not them, even though to me, that seems like a binary value
Template binary can turn anything into an on/off type sensor.
ahhh ok
in my example it's in your case 22 "or else" and I think that's fine
This line threw me: These sensors only have two states: 0/off/low/closed/false and 1/on/high/open/true. K
Which is why I said about 'Closed' not being the same as 'closed'. HA's states are lower-cased.
Once you make a sensor with the right states, everything else will understand it.
That makes sense. I thought the area I put closed, I could put whatever I wanted the value to display
Docs are "guidelines", you can do more than what's documented, if every possible use case was documented, it would be so much that you would never find anything
You could... but it wouldn't follow the same pattern as everything else.
I thought I could put "MIL LEFT THE DOOR OPEN!!!"
ok... i'll go back to the drawing board. Also, i noticed you all short handed the templates. Is there a tutorial on doing that? looks much easier
Like the others have said... you're basically making a binary sensor. Might as well use the right tool for the job.
Aight, so oddly enough this works for the icon, but the door always says Closed in lovelace.
https://paste.ubuntu.com/p/JS9PztXtgr/
I tried switching the '22' -> 22 thinking it was something to do with the string vs int but that didn't do the trick
What was your config for the sensor in the end?
Or is that the binary sensor?
Because if it's a binary sensor, you need to understand this bit:
value_template template REQUIRED
The sensor is on if the template evaluates as True and off otherwise. The actual appearance in the frontend (Open/Closed, Detected/Clear etc) depends on the sensorβs device_class value
I moved it to the binary sensor section of my config and the code above is what I used.
so i need to change the open == on and closed to off?
making that change.
No, the value template should just be "{{ is_state('sensor.guest_room_door_access_control', '22') }}"
The template needs to evaluate as True or False
It just says 'is the state of sensor.guest... equal to 22?'
Put that in the template tool at dev tools > template
'Is it 22?' only has two answers... yes or no π
That's what makes the binary sensor binary.
binhairy sensor
I template very rarely (obviously) so I'm extremely green and confused on it.
Don't worry, binary stuff is tricky.
They say there are only 10 types of people. Those that understand it and those that do.
lol
So one additional question. That worked btw, but i've got other door sensors (non zwave) is there a way to template them all in a similar way? I like the way this one shows up in my lovelace
There are two kinds of people: those who can extrapolate missing data
the api give only temperature as value decimal
how to get that value using template ? π this is a commnad line with curl get
Done thanks π
hi! Can someone help me about my problem? π
when i try to use this template in the template editor:
{% set zipped = dict() %}
{% set options = state_attr('input_select.options', 'options') %}
{% for i in (range(1,3) | list) %}
{% set key = options[i-1] %}
{% if key in options %}
{% set _ = zipped.update( {key: i} ) %}
{% endif %}
{% endfor %}
{{ zipped }}
i get the error: SecurityError: access to attribute 'update' of 'dict' object is unsafe.
I have home thermostat which i set up with sonof R3 basic wifi and one reley, because i have radiators valves with temeprature senzors. So, the only way to have some kind off smart on/off thermostat is this way. When sonoff switch is on heating is off, ande when sonoff switch is off, heating is on. Sounds stupid but it works. So my question is ; I have made generic thermostat and pair it whit xiaomi sensor and sonof switch, but problem is state of switch..When I set desired temperature of 25 sonoff switch set to on and heating is off
i'm trying to "zip" the list of options from an input_select with their respective indices
could anyone offer guidance? i had hoped i could do it with a dict comprehension, but it didn't quite work out as i'd hoped
use namespace
?
Variables defined/used inside a loop vanish once outside the loop
Namespaces fix that
{"sensors":{"28-00000b988fef":"38.0","28-00000b98f5e6":"36.25","28-00000b9905e1":"40.375","28-00000b9920f3":"44.5","28-00000b994f64":"40.437","28-00000b9951c4":"36.812","28-00000b996c8c":"39.75","28-00000b99a737":"32.875","28-00000b99a884":"33.062","28-00000b99b4f0":"39.062","28-00000b99f29e":"37.812","28-00000b99fa3c":"34.062","28-00000b9a170e":"40.125","28-00000b9a1ca5":"41.562","28-00000b9a2529":"31.875","28-00000b9a3025":"42.062","28-00000b9a444d":"45.625","28-00000b9a4668":"46.125"}}
how to get the first sensors value ?
value_template: '{{ value_json["sensors"][0]["28-00000b988fef"] }}' Seems not to be working
{{ value_json.sensors["28-00000b988fef"] }}
There's no array in what you've shared, so you don't need to do [0] to get the first thing.
You just reference them by name instead.
You might also want to turn the result into a float (decimal number) instead of a string too:
{{ value_json.sensors["28-00000b988fef"] | float }}
I have a template to turn on my TV, and another to turn on my AV Receiver. Can i combine them into one?
Templates that turn things on? What is this strange magic you speak of?
yea i figured something was wrong as i was saying that
it's a switch and a template sensor
*value template
- platform: template
switches:
denon_heos_music:
friendly_name: Denon HEOS Music
value_template: >
{{ is_state_attr('media_player.denon_avr_x1500h', 'source', 'HEOS Music') }}
turn_on:
service: media_player.select_source
data:
entity_id: media_player.denon_avr_x1500h
source: 'HEOS Music'
turn_off:
service: media_player.turn_off
entity_id: media_player.denon_avr_x1500h```
not the same thing as a template then?
It makes use of templates. That doesn't make the whole thing a template.
It's more of an #integrations-archived question really π
got it. thanks Mono!
You might also want to turn the result into a float (decimal number) instead of a string too:
{{ value_json.sensors["28-00000b988fef"] | float }}
@ivory delta Did not work π¦
- platform: command_line
name: Ds1test
command: "/usr/bin/curl curl -X GET http://192.168.40.210:8080/rest/api/v1.0/temperature "
scan_interval: 3
unit_of_measurement: C
value_template: '{{ value_json.sensors["28-00000b988fef"] | float }}'
Use the Dev Tools to test it.
> Templates
You'll see there's an example like this:
{% set my_test_json = {
"temperature": 25,
"unit": "Β°C"
} %}```
aha π
You can set your JSON there... and below that, experiment π
β€οΈ
You can set your JSON there... and below that, experiment π
@ivory delta am i doing it right
{% set my_test_json = {"sensors":{"28-00000b988fef":"42.312","28-00000b98f5e6":"51.937","28-00000b9905e1":"39.062","28-00000b9920f3":"39.062","28-00000b994f64":"37.625","28-00000b9951c4":"37.812","28-00000b996c8c":"38.0","28-00000b99a737":"33.687","28-00000b99a884":"33.25","28-00000b99b4f0":"38.937","28-00000b99f29e":"37.75","28-00000b99fa3c":"34.187","28-00000b9a170e":"36.562","28-00000b9a1ca5":"37.75","28-00000b9a2529":"32.375","28-00000b9a3025":"40.187","28-00000b9a444d":"42.125","28-00000b9a4668":"41.312"}} %}
The temperature is {{ value_json["sensors"]["28-00000b988fef"] }} {{ my_test_json.unit }}.
thanks π
That looks okay. Does it work for you?
no π¦
Do it in small steps. Try {{ value_json.sensors }} and see what that shows.
still nothing
Oh... don't use value_json... use my_test_json here π
Or rename my_test_json to value_json.
The name doesn't matter as long as they match.
This works for me:
{% set value_json = {"sensors":{"28-00000b988fef":"42.312","28-00000b98f5e6":"51.937","28-00000b9905e1":"39.062","28-00000b9920f3":"39.062","28-00000b994f64":"37.625","28-00000b9951c4":"37.812","28-00000b996c8c":"38.0","28-00000b99a737":"33.687","28-00000b99a884":"33.25","28-00000b99b4f0":"38.937","28-00000b99f29e":"37.75","28-00000b99fa3c":"34.187","28-00000b9a170e":"36.562","28-00000b9a1ca5":"37.75","28-00000b9a2529":"32.375","28-00000b9a3025":"40.187","28-00000b9a444d":"42.125","28-00000b9a4668":"41.312"}} %}
The temperature is {{ value_json["sensors"]["28-00000b988fef"] }}```
The temperature is 42.312
Thank you soo much works for me
i will test it live
you are the best β€οΈ
my rockstar π hahaha
but when it comes to live its not working ... this is crazy ..
- platform: command_line
name: testingnow
command: "/usr/bin/curl curl -X GET http://192.168.40.210:8080/rest/api/v1.0/temperature "
scan_interval: 3
unit_of_measurement: C
value_template: '{{ value_json["sensors"]["28-00000b988fef"] }}'
the only reason why am using command-line is becase rest will exceed 255 characters
and i got this command working otehr places its a coppy paste and edit ..
I think you can use REST for long responses. You just can't set the state to something longer than 255 characters.
By default, the sensor state would be set to the full JSON β here, that would exceed the 255-character maximum allowed length for the state, so we override that default by using value_template to set a static value of OK.
@inner mesa i guess i don't get how namespaces help? the template won't allow me to use update on a dict, which should be in scope
ahh ok, lemme see
like this?
{% set ns = namespace(zipped={}) %}
{% set options = state_attr('input_select.options', 'options') %}
{% for i in (range(1,3) | list) %}
{% set key = options[i-1] %}
{% if key in options %}
{% set _ = ns.zipped.update( {key: i} ) %}
{% endif %}
{% endfor %}
{{ ns.zipped }}
I believe so. Does it work?
Same with options
oof, oh yeah
{% set ns = namespace(zipped={}, options=state_attr('input_select.options', 'options')) %}
{% for i in (range(1,3) | list) %}
{% set key = ns.options[i-1] %}
{% if key in ns.options %}
{% set _ = ns.zipped.update( {key: i} ) %}
{% endif %}
{% endfor %}
{{ ns.zipped }}
same error here, but removing the ns. on line 4 actually does render
it renders {}
actually it renders if i remove the one on line 5 too
That set line in the loop looks wrong
You are not allowed to use update
We are running sandbox
i think i need to do something like ns.zipped[key] = i?
allowing update, would mean you would acually update the state objects
wait what? ns.zipped in my template is a dict i create and populate
so there isn't really a way to do this then?
for example, if my input_select has ['A', 'B', 'C'], i want to end up with something that has {'A': 1, 'B': 2, 'C': 3}
You can change the ns elements inside the loop
... is that not what the template above attempts to do?
i have that
{{ state_attr('input_select.options', 'options') }}
{{ range(1,4) | list }}
gives me
['A', 'B', 'C']
[1, 2, 3]
so now want to zip those together
in python it's zip(list1, list2), done lol
hey just wondering if someone could help me getting the cost for electric usage? please
yes i did
it's just an extremely vague question
i have code in the yaml but its not adding up
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
answer could be "visit website of power provider"
yea but right now i only got a ps4 plugged into it
so cant be that much
only flashed the plug an hour ago
did you manually do the math?
||nope||
yes i did but i tried to use it but didnt do much
2 things could be happening
- energy meter not calibrated
- energy cost is off
Explain the math you want to use.
And explain why you think the HA sensor is wrong.
You're not giving us much information here, so we can't tell you what's wrong.
7β¬/h playing ps4 π€£
uffff
2 things could be happening
- energy meter not calibrated
- energy cost is off
@warm isle ill try the first one now
54w /1000 then * .136 right
13.6c / kWh?
yea
So... where's your kWh? I only see W and β¬
You need to give us all the information. Don't just give small pieces...
Anyway, I'm outta here. Good luck.
ok
my guess now is that you use the watage instead of kwh for calculating prices
so i can use the total kwh?
uuuuuuhhhmmmmm
How would you otherwise calculate β¬ out of it
templates
what does "{{ (states('sensor.charger_hourly') }}" give you
http://<<ip or url>>/developer-tools/template
gives me 0.01
odd.. and the full
{{ (states('sensor.charger_hourly') | float * 0.136) | round(2) }}"
0.0014
that makes no sense
that looks right, but why you get 7.75 ? restarted while there
(pssst... current hour)
that's the |round(2)
yea, set back the round to 4
This conversation started before the hour. Things have changed.
your template tells you 0.0014
so thats right, restart ha and look if the numbers changing
youmaybe looking at the wrong sensor
dont forget to press the check config button
will do
is this still a thing btw? back in the days with hassbian it was a terrible thing when you just restarted π
Template sensors can be hot reloaded now
not taking changes now π
Spoiler alert... the current config is right but you didn't tell us about all the changes you made in the previous hour.
The sensor has a history. It still has the 'wrong' data from before you changed it.
is there a way to clear the history?
Delete your database.
And this is why providing all of the information in the first place is so important.
Several people were trying to troubleshoot a non-issue.
@blazing burrow how is your isue going?
not that I'm able to help, but intrested if you where able to solfe it
no, i moved onto something else for a bit
Would 'need' something simalar for a telegram bot, one of the many abandoned things
db deleted and restarted,same values still there
mine is for mapping named options in an input_select to integers to send to wled api
i have a reasonable solution already, just looking for something cleaner/more general
aah I know these stuggles
lol
feel free to ping me when you got it, interested:)
π
.away zZzzZZz late in π¦πΉ
Underknowledge is away! zZzzZZz late in π¦πΉ :wave:
i could do it in a second in python, in like a bunch of different ways π
<6 hours later> Success! I finally have it working exactly as well as it worked 6 hours ago!
victory! lol
@wooden tangle Just curious, did you solve it?
I noticed you have configured utility meters, does they work as expected?
for the usage yes but not the cost
ok, I haven't followed everything here, but if you put {{ states('sensor.charger_daily') | float }} into dev tools, what's the response?
that seemed to be the utility meter, right?
0.01
{{ ((states('sensor.tumble_dryer_total_daily_energy') | float) * 10) }}
just want to make sure here..
sorry
np
{{ ((states('sensor.charger_daily') | float) * 10) }}
0.1
ok, and finally {{ ((states('sensor.charger_daily') | float) * 0.14) | round(2) }} where you replace 0.14 with your price per kwh
0.0
there it is π no cost so far today
remove the round and take it * 1000 just to see it works
..or try the {{ ((states('sensor.charger_monthly') | float) * 0.14) | round(2) }} , I guess the monthly have a value a bit higher still?
0.0 because i just reset it all
oh
it had the history of previous mistakes but ill leave it now and see
if you take it * 10000 instead of you price, you should see results pretty soon
no?
It's working, just leave it.
It was working before the discussion even began,.
At some point before Galaxy started asking for help, they'd already had the right configuration. They just gave poor information.
might just go and boil the kettle π , yea kinda just had to reset i guess
just a note: but when I said "take it * 10000 instead of you price, you should see results pretty soon", I meant in dev tools, that can hardly introduce bad data again?
or am I missing something more here?
A little, yes. The templates that Galaxy shared were good. No apparent problems with how they looked and they gave all the right results in dev tools.
The only problem is that before they asked for help, they must have already tried incorrect templates on their live sensors. Their database had bad history, so they thought there was a problem still.
i appreciate the help from the 3 of you guys, hopefully it will be fine from here on out.
and yea it was that and trying maths equations too
looks good so far
just used the kettle to boost it
Hi everyone! I'm trying to make an automation to set the time value of an input_datetime entity to the next hour (eg. if the current time is 15:19 set the time value to 16:00). Am using the automation editor, have set up the trigger and the action (call service input_datetime.set_datetime), it's just the template stuff for the service data that I'm having trouble figuring out. I think I want to pull the hour from states('sensor.time') and add one to it (watching out for the case around midnight where it needs to go back to zero), and then express that as a time in the correct format for the service to understand, but I'm not sure how to do that - or if there's a more elegant way?
I am new to HA but I wonder if something like this would work
{{((as_timestamp(now()) + (59 * 60 + 59))) | timestamp_custom('%Y/%m/%d %H:00:00 ')}}
So it adds an hour less one second and then you have the year,month and hour and just set the minutes and seconds to zero.
Thank you, sounds like it could work. I don't need the date, just the time, but I can leave those bits out. I'm not quite sure how to put it into the automation editor in the right way for it to understand it either, I'm pretty new to this too
Ok getting there with that part at least
Google suggests that you can not template the setting of the value on an input entity and I can't get the developer tools to let me, what were you going to the use the field for. You could use a time trigger directly if you just want to trigger something on the hour.
You don't use the template to set something. You use the template as part of something.
It's valid to pass a template as the argument to a service. Its value will be evaluated and passed to the service.
Example:
action:
service: "homeassistant.turn_{{ trigger.to_state.state }}"
data:
entity_id: group.landing_switches```
Ok thanks, so I know I can set the service data to time: '{{template}}' - I just need to figure out the template
Also some stuff from google led me to believe that now() isn't necessarily up to date and I should use sensor.time
It used to be that now didn't update templates. I think that may have changed.
You'll find out if you test your templates in the Dev Tools. It has a hint under the right hand side to say what will trigger re-evaluation.
Oh ok, that's useful thanks
This template does not listen for any state changed events and will not update automatically.
correct, once a minute as of 0.117: https://www.home-assistant.io/blog/2020/10/28/release-117/#breaking-changes
The 'will not update automatically' is a little misleading π
It's just less frequent. If once per minute is good enough for your use case, stick with now().
And that only matters for triggers anyway. If you're using it in an action, it'll evaluate on demand.
Oh ok that's great then, thanks - now() will be fine
sorry, should have been clearer about what was correct π
All good, thank you π
Using @lyric comet 's original suggestion, this seems to work now: time: '{{ ((as_timestamp(now()) + (59 * 60 + 59))) | timestamp_custom("%H:00") }}'
Tho I don't know what happens around midnight
You can test it in the Dev Tools and find out
Ok I remembered about modulus, and I decided to try another approach, now I seem to have got the hang of formatting it. Now I've got time: '{{ (now().hour + 1) % 24 }}:00'
Test run seems to work, gonna see what happens in 5 minutes
Oh, that's a nice approach π»
You did the work in the end π
Hi!
I am trying to get sensor data from a string, which looks like this:
data:
- datetime: '2020-11-15T16:00:00.000Z'
value: cloudy - datetime: '2020-11-15T17:00:00.000Z'
value: rainy
I am trying to make a sensor, which grabs the weather conditions at particular times for today and tomorrow. Im not a programmer and Ive been trying to get the data but i have not succeeded.. can anyone help me on my way?
HI π how to make this work ? {% if value_json.getitem('404 Not Found')) %} ?
i wanne check if value_jason contain that
@fossil hearth {% if value_json[β404 Not Foundβ] %}
{% if β404 Not Foundβ in value_json %}
invalid template ..
@fossil hearth posted a code wall, it is moved here --> https://paste.ubuntu.com/p/YfKn4K2mVB/
all gd i just had to restart it
@fossil hearth you need to wrap it in quotes. or use multiline notation. Also, that code requires that CustomUI is installed.
sensor.rpi_milksensor_script_process_1: icon: mdi:application icon_color: templates: > return (state === 'S') ? 'rgb(67,167,47)' : 'rgb(219,27,8)';
@mighty ledge installed the custom UI sucsefully but still not working ? do i need to add a command somhwere ?
Hi everyone, I am looking for a way to perform an action on several entities based on a regex on their names.
I'd like to run a loop like that : {% for entity_id in all_entities | regex_match("switch.schedule_*") %}
to perform the action on all my switch.schedule_*
These entities are generated directly through a card, from the UI, so I do not really know how many there is and this can change during the run
But I'd like an input_boolean to deactive/active all.
@waxen rune thanks a lot, that's a great idea!
Don't know what you mean, but I'm glad to help π
@fossil hearth clear your cache and reload the page
Hi :)
does anyone have a way to use this as a trigger
"{{ expand('group.battery') | map(attribute='state') | map('int') | select('lt', 15)|list |count > 0 }}"
but have it ignore 'unavailable' state ?
map(attribute='state', default="100") don't work because 'unavailable' is a value
well i didn't think hard enough π€¦ I've been on this for week, but just now think about map('replace', 'unavailable', '100')
thoughts on how to elegantly add trigger.for into else portion of
switch.turn_{{ 'off' if trigger.to_state.state == 'home' else 'on' }}
too screwy for oneliner?
What do you want it to do?
it being instant on home value and wait for x minutes for else value
What does your trigger look like?
Yep, I've gotcha
dont want to make multile automations and keep it clean if possible π things must wait when i leave but not keep me in dark-cold for x minutes when i return
So do you just care about home/not_home with this automation?
thats what it does yeah, just want to modify the else 'on' into else trigger.for 10 minutes ... 'on'
Let's jump to #automations-archived
ok
@arctic sorrel https://hasteb.in/goveludu.yaml probably
This again lists multiple URLs under same category . How do I differentiate different URL triggers?
I didn't say that'd solve that problem
https://www.home-assistant.io/integrations/feedreader/ - look at the examples
action:
service: persistent_notification.create
data:
title: "New HA Podcast available"
message: "New Podcast available - {{ as_timestamp(now()) | timestamp_custom('%I:%M:%S %p %d%b%Y', true) }}"
notification_id: "{{ trigger.event.data.title }}"
trigger.event.data contains information about the new entry, the docs show that at least title and content exist
Also says:
Any field under the
<entry>tag in the feed can be used for exampletrigger.event.data.contentwill get the body of the feed entry.
So, you can use similar logic for anything else in that tag
I have looked at all examples... no example is about differentiating triggers from different URL feeds. How does trigger.event.data help me differentiating content from different feeds? That would be different for all feed URLs every single time a new feed gets published in rss.
I dont think you are even reading my problem than spamming me to read the same link (and earlier devices link which seems nothing to do with my query)
Good news, we're all volunteers here. I don't have to help you, and I'm done here
And btw "trigger.event.data.content" is broken. It doesn't work. No feed content gets fetched. Do I need to open github issue for that?
Ok thanks very much. So much for slamming new users to every channel and posting unrelated links than understanding the query. And then giving lecture on "teaching to fish " , even if someone tries
Dude, this is free help. No one is obligated to help at all and there's no guarantee any help you receive will fix the problem. Sorry if it's not up to your standards, maybe you can apply for a refund
Yeah may be "volunteers " stop ranting that they are teaching to fish and the other person should try. When the other person does try and make something work, all they do is posting same links which have nothing related to next related query.
And then its easy to say " I dont know if it works or not or even related . Its free help. I am a mod. I can misguide new users without any responsibility and spam them to various channels for related questions "
Right ? Wow
π€£
You ain't seen me rant... and I've posted you at the relevant links to the questions you've posted.
Also, no, I don't know how to do everything. There's 1713 integrations. I don't use all of them, nobody does.
None of us here are trying to misguide users or "spam them to various channels"
There are channels for a reason. People who help look at specific channels
Turns out that my answer above is right though, it will work with the right tag in trigger.event.data
Yeah making large emojis helps. Nice. Speaks loud of how responsible you are as a volunteer (mod) .. lol
Well that looked fun π
Can someone help me getting my solar template to work
SENSOR.YAML
sensor:
- platform: template
sensors:
#This is converting the Solar Energy to KWH#
solaredge_energy_today_kwh:
friendly_name: 'Solar Today'
unit_of_measurement: 'kWh'
value_template: "{{ (states('sensor.solaredge_energy_today') | float / 1000) | round(2) }}"
This is in my Config.YAML
?
I have solar panels and want to get the information to the dashboard. I did my googles and it told me to create a template for the sensor
its all very confusing
What is wrong?
When I add this information to my config file. I thought I should get a new entity called "solaredge_energy_today_kwh"
but i dont seem to get anything. I might be all wrong in how this works tho
How do you get these informations Pixels ? You get some solar panel but what's giving you the production metrics ?
You mention both sensor.yaml and βconfig.yamlβ Where did you put that?
@inner mesa i put the info above in my config.yaml
I dont have a seperate senor.yaml file
it was a comment to myself to keep a bit organized in the config yaml
Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.
Ok, thatβs gonna be confusing
Ok; I have a bunch of small inverter thats why I do not have the same setup. On my side I am using an ESPhome integration.
How do you request your inverter ?
I used the HACS they have a solaredge add on
I entered my site ID and it was able to pull up all the info
You didnβt format your code, so itβs hard to know whether itβs correct...
Would a screencap be better?
No
How to formate my code?
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/.
'''
@surreal stratus posted a code wall, it is moved here --> https://paste.ubuntu.com/p/DzfQCyVxqx/
yep, before and after the code section π
Sigh
Sorry, did i do that correct?
yes
Except for this bit:
For over 15 lines you must use a code share site such as https://paste.ubuntu.com/ or https://www.hastebin.com/.
No codewalls please.
~codewall @surreal stratus π
@surreal stratus 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.
Hum, I'm not a jinja killer, but (states('sensor.solaredge_energy_today') | float / 1000) | round(2) shouldn't it be ((states('sensor.solaredge_energy_today') | float) / 1000) | round(2) ?
How do you test it ?
I tested in the template tab
That should be okay as-is
That should be okay as-is
@inner mesa okay. should I get a separate entity?
Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.
Check shows up as green
have you restarted or reloaded the templates?
I have. I get a log error saying that the sensor took too long to respond
Should I do something for it to show up in the front end?
it doesn't sound like you ran the config check
I'm curious if there is a problem with the template (which seems fine to me) or with the actual sensor sensor.solaredge_energy_today
it doesn't sound like you ran the config check
@inner mesa I thought the green check box thingy was the check. Going back to google to get more info
no, I've posted the bot message twice now
oh ok! i see it
doing it now
sorry suppppperrr new to this. Still trying to get my bearings
I think the bot messages are invisible to new HA users π
Is there a way to perform an action on all entities matching a pattern ?
depends on what that action is
2020-11-16 11:49:53 WARNING (MainThread) [homeassistant.components.sensor] Updating solaredge sensor took longer than the scheduled update interval 0:00:30
Could this be because im using Duck DNS and not on my home network
I am using a card which is creating some switch, everyone can create several ones. I would like a "super button", so an input_boolean to set all of them off or on.
I was thinking about doing something like :
{% for entity_id in all_entities | regex_match("switch.schedule_*") %}
{{- entity_id }}
{% endfor %}
I don't think I could make that format work
it's the right idea, but comma-separated worked for me
whats an other way to reset entity history. i tried deleting the db but its still there
@wooden tangle you can only delete the history if home assistant is off.
@thorny snow
{% set ns = namespace(entities=[]) %}
{% for s in states.switch if s.object_id.startswith('schedule_') %}
{% set ns.entities = ns.entities + [ s.entity_id ] %}
{% endfor %}
{{ ns.entities | join(', ') }}
petro; ns is for generating a var with all entities ?
namespace allows you to create a variable that persists across for loops
i created the variable 'entities' inside the namespace named ns
so to access, you use ns.entities
ok, got it, but I think I do not need to create this var. Thanks a lot for this I did not known
states.switch seems contains everything I need
are you going to add more switches?
if so, you'll probably want to use the template.
otherwise you'll shoot yourself in the foot when you add another switch
Yes I'll add more switches, thats the point otherwise I could have done it without templates :/
Then you'll want to use the template
yep
I tested it and it works well, (without ns part, since there is a fault with the ',')
You may run into problems if you have an extra comma at the end
that's why I went with NS
ok
so as in turn it off then on or off for abit
with NS, you can just simply join the list together with commas
Turn off home assistant. Delete database. Turn on Home assistant.
this will require you to use SSH
ok, I was doing it with {%- if not loop.last %},{%endif%}
So I am doing the check with : {%- if not loop.last %},{%endif%}
sorry wrong paste : {% for i in states.switch if i.object_id.startswith('schedule') %}
which check if entity_id is starting with schedule; this is almost what I need: I would liked to check friendly_name. So if object_id is entity_id, what is friendly_name ? π
π€ I hope I can adress it from there ....
just done it and nothing changed strangely
I tested i.friendly_name i.name i.attributes.friendly_name as described in https://www.home-assistant.io/docs/configuration/state_object/
I cannot find what is the name of the dict entry to get the friendly_name .... What is i here ? a state objects ?
What does return states.switch ?
it's an attribute
this spits out the friendly names for me:
{%- for i in states.switch if i.object_id.startswith('fr_') -%}
{{ i.attributes.friendly_name }}
{%- endfor %}
My switch is entity_id is switch.schedule_68da99 and when having a look on developper tab; it has : friendly_name: schedule_bed2_weekend
so it is its friendly_name; this switch has been generated by scheduler_card; this have set the optional friendly_name
ok
Is there a way to list content of states dict ?
all the attributes?
{{ states.switch.fr_wallmote_switch.attributes }}
I'm tired about blind shots ^^ I need lights ...
{'node_id': 36, 'friendly_name': 'FR Wallmote Duo Switch'}
Here I would liked to search "FR 3 in your example ^^
i.friendly_name.startswith('FR ')
But you gives me * {{ states.switch.fr_wallmote_switch.attributes }} * which seems good, but where can I set it and see he result ?
WOW Big thank !
Amazing ... The french translation for template is "modèle" which can be quite good but in this context I never understood this tab ^^
you can type whatever you want there and it evaluates in real-time
I though it was to generate some text to make some "strange" reports
this tool will definitively help me so much
thanks for turning this light on ^^
@thorny snow object_id is the object_id. entity_id = domain.object_id. So for switch.laundry, the domain is switch, the object_id is laundry, and the entity_id is switch.laundry.
to get the friendly name off the states object, it's simply just .name instead of .object_id
So it should be that : {% for i in states.switch if i.name.startswith('schedule') %}, isn't it ?
if you use i as the states object, yes.
you can also get the friendly name through the attributes
i.attributes.friendly_name
When I'm doing it in the dev tool I got the right value : switch.schedule_68da99=schedule_bed2_weekend
But When I set it into my automation template with this if ... I get this issue
what are you using in the dev tools?
voluptuous.error.MultipleInvalid: not a valid value for dictionary value @ data['entity_id']
In the dev tools (template tab π @inner mesa ) it works as you described
post your configuration in the automation and post what you're putting in dev tools
- alias: Start/stop chambre enfant schedule
trigger:
platform: state
entity_id: input_boolean.bed2_schedule
action:
data:
entity_id: >-
{% for i in states.switch if i.name.startswith('schedule') %}
- {{ i.entity_id }}
{% endfor %}
service_template: switch.turn_{{ trigger.to_state.state | lower }}
yes you're right, but I did not yet understood why ^^
How yep thx, I mixed up the configs
this is because the entity_id field accepts a list or a single value
got it
a listed item is denoted with a dash (-) in yaml, but templates only output single values
didn't that change in 0.117?
yet it still didn't work when I tried it earlier
that was during the 0.117 beta
and that's why I mentioned the comma-separated version
with the new template stuffs you can output a list object and that'll work
- alias: Start/stop chambre enfant schedule
trigger:
platform: state
entity_id: input_boolean.bed2_schedule
action:
data:
entity_id: >-
{%- for i in states.switch if i.name.startswith('schedule') -%}
{{ i.entity_id }}
{%- if not loop.last %},{%endif%}
{%- endfor %}
service_template: switch.turn_{{ trigger.to_state.state | lower }}
you just want service: there, not service_template:
What's teh difference .... I was thinking I was needing it as soon as I was using some jj2 ...
the _template version of service and data were deprecated back in 0.115
it's probably showing a warning now
you don't need them anymore - templates are always accepted in data: and service: blocks
ok, thanks
{%- for i in states.switch if i.name.startswith('schedule') -%}
{% set ns.switches = ns.switches + [ i.entity_id ] %}
{%- endfor %}
# with new stuff
{{ ns.switches }}
# old method
{{ ", ".join(ns.switches) }}```
looks like more characters
I already posted that solution a while ago but he didn't want it
it's the same thing
lol yup
it has the same result as what I posted
nope petro; you posted : {{ ns.entities | join(', ') }}
same thing
yep
and this gaves me a syntax issue and since RobC posted before the {%- if not loop.last %},{%endif%}, (that I am usually using in ansible) I used his syntax
@inner mesa in .117 you don't need to join the list with commas, but I'm not sure if it will work because thats a special case
entities has always been a special case. We pass a comma separated string to entities and it works. It's the only field where a comma separated list will work
otherwise you'll need a 'real' list object or a single item
But I keep in mind your syntax about namespace, it will help me I think π
I noticed that when I tried to create a list of states
yeah it's an oddball for sure
for the most part, this will work now as @dreamy sinew said:
{% set ns = namespace(switches=[]) %}
{%- for i in states.switch if i.name.startswith('schedule') -%}
{% set ns.switches = ns.switches + [ i.entity_id ] %}
{%- endfor %}
{{ ns.switches }}
the fact that it can live outside of data:, but with reduced functionality is also weird. but less typing, I guess.
what do you mean?
that will output a list
entity_id: can live both inside and outside data:
@dreamy sinew yah 117 and 118 should accept that now
but outside of data:, you can't use templates
Ah yes, that's also a caveat
i think inside data was a workaround for that reason
and no one went back to deprecate out the outside one
yeah, definitely not now
and it's nice for shorthand
it isn't and won't
you mean the _template: variants?
oh
I thought it did spit out a warning, unless it changed
I've seen people ask/complain about it
looks like it's just a tooltip in VSCode
I'm just now diving into templates finally (like three years later) - I'm trying to create a sensor to pull the temperature attribute out of the weather.home component does anyone have like a good baby step to get my feet yet
because I already messed it up trying to add it to my sensors.yaml lol
use the template editor in dev tools
yeeeet
thank you
That helped - I got the temperature to pull out correctly now I know it's in my sensor.yaml file I'll keep pecking away thanks!
Go figure... it was my indentation again I mentioned in the automation channels lol
IT WORKED THANKS @mighty ledge wooooooo
Now I can run my freeze protection on the pool using the weather card data instead of a thermometer I have in the ground lol
@dire flare Is the sensor you have in the ground bad? I feel like I would trust that over the weather π€£
{{ -3 < ((as_timestamp(now()) - as_timestamp(states.image_processing.doods_front_camera_snapshot.last_updated)) < 2 ) }}
is basically
{{ -3 < MAGIC < 2 }}
It'll return true if MAGIC is between -3 and 2
Go and drop ```
{{ as_timestamp(now()) }}
What is?
When I put {{ as_timestamp(now()) }} in developers, I get a string with explanation updates the start of each minute
You don't care about how often it updates, you care about what it represents.
It's a timestamp that represents 'now'.
I'm guessing your template means... if processing is from now between -3 and under 2, proceed?
The number is a value in seconds
The time is in 'seconds since the beginning of 1970'.
All that template does is make sure that the entity has just updated
Yes, I want to adjust it, because I get notified with your script. It shows me There was motion at the front at 2020-11-16 21:16:01.
We saw nothing of importance.. While I see the current camera snapshot and processed image attached
I'm guessing it's being processed too quick because I'm using tflite model
Well, you've two things to check:
- That the
image_processingentity has information - That the monster script produces output that's got "interesting" things
I don't really understand the interesting things input number either π
You're trying to fly before you've worked out to crawl
You are absolutely right!
Get Doods producing useful output
Until you get that working, don't do anything else
Tensorflow models are processing way too long
I'll try more troubleshooting. Not sure what direction to look at
I've reduced the resolution of my main camera stream and made sure cpu usage is minimum... Yet doods comes and uses every % of CPU, and causing delay.
To be expected on your hardware