#templates-archived
1 messages · Page 97 of 1
is generic_thermostat also looking for the unit_of_measurement state_attr as well?
well, I can mess with it, and dump it in a template sensor if needed
I don’t know what condition you’re trying to satisfy
You have a number that happens to be a temperature and you want to use it as data for a service?
My end state is this: I need to give generic_thermostat a target_sensor which I assumed needed to be a sensor entity.
The target sensor needs to be based on "occupancy" behavior, using input_booleans. If an input_boolean is true, then its corresponding sensor can be inlcuded in the calculation. Ultimately the highest/lowest temperature is used as the target_sensor temp
hopefully I am making some sense, its all jumbled in my head trying to figure out how to accomplish this
I haven't seen or used generic_thermostat before, but I see it now
you can replicate everything in your screenshot in a template sensor based on an input_number
device_class, units, etc.
if it cares about all that. I'm not sure what it means by "must be a temperature"
as in, what it checks to ensure that
but you can make it look however you want
yeah that was a little unclear to me too, but I think youre right that storing in a input_number and manipulating that via automations is the right call here
I was trying to do too much within a single template sensor
there are a bunch of hits on the forum for things like "generic_thermostat input_number"
that's usually for "temperature", but I would think it would apply to any of the sensor values
kinda the point of generic_thermostat, it seems
Alright let me give this a shot. Thanks a ton for the help!
np, good luck. come back with any questions
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
Hello, I would like to calculate total cost of power usage. I have a sensor which gives me the total KWh. So I would like to multiply this with 0.21 to gove met the amount in euros. Thhis is what I have in sensors.yaml:
https://hastebin.com/mekafaheya.bash
But unfortunately this isnt working. What am I doing wrong?
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)
Which bit isn't working?
I get an error in HA.
Invalid config for [sensor.template]: expected a dictionary for dictionary value @ data['sensors']['friendly_name']. Got '“Net Power”'
expected a dictionary for dictionary value @ data['sensors']['netpowercalc']. Got None
expected a dictionary for dictionary value @ data['sensors']['value_template']. Got '{{ ((states.sensor.switch_hs110_1_total_kwh.state | float * 0.21)) | round(2) }}'. (See ?, line ?).
Wrong tab spacing
On the last one
sensors:
netpowercalc:
value_template: '{{ ((states.sensor.switch_hs110_1_total_kwh.state | float * 0.21)) | round(2) }}'
friendly_name: "Net Power"```
Really??? This took me two daysfiguring out what was wrong with the value_template part. I don't have experience with this so I tried to copy examples and adjust to my sensors. I don't have an error now so I will check if the calulation goes as planned. Thank a lot!
I find it very difficult to distinguish indents in the file editor of HA. I can access the files also through Samba. Is there a better editor for editing yaml. files? Under Windows 10
visual studio code or sublime text
Thnx. Is it possible to directly (samba) get access to the files and is there an error warning available as i the editor of HA? Both look promising
VSC has a HA addon that enhances the editing with entity_id autocomplete nad more
you can access all your yaml files with samba or sftp
Thnx! VSC it will be
Having trouble with this service template
action:
- service_template: switch.toggle
data_template: >
{% if is_state('input_boolean.alex_sound_trigger2','on') and is_state('input_boolean.alex_movement_trigger2','on') %}
entity_id: switch.telnet_alex_unsettled_both
{% elif is_state('input_boolean.alex_sound_trigger2','on') and is_state('input_boolean.alex_movement_trigger2','off') %}
entity_id: switch.telnet_alex_unsettled_sound
{% elif is_state('input_boolean.alex_sound_trigger2','off') and is_state('input_boolean.alex_movement_trigger2','on') %}
entity_id: switch.telnet_alex_unsettled_movement
{% elif is_state('input_boolean.alex_sound_trigger2','off') and is_state('input_boolean.alex_movement_trigger2','off') %}
entity_id: switch.telnet_alex_unsettled_none
{% endif %}
it works ok in the template editor
Invalid config for [automation]: expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None. (See ?, line ?).
@snow zenith posted a code wall, it is moved here --> https://paste.ubuntu.com/p/pVybwhDYfQ/
Fixed it
- service: switch.toggle
data_template:
entity_id: >
{% if is_state('input_boolean.alex_sound_trigger2','on') and is_state('input_boolean.alex_movement_trigger2','on') %}
switch.telnet_alex_unsettled_both
{% elif is_state('input_boolean.alex_sound_trigger2','on') and is_state('input_boolean.alex_movement_trigger2','off') %}
switch.telnet_alex_unsettled_sound
{% elif is_state('input_boolean.alex_sound_trigger2','off') and is_state('input_boolean.alex_movement_trigger2','on') %}
switch.telnet_alex_unsettled_movement
{% elif is_state('input_boolean.alex_sound_trigger2','off') and is_state('input_boolean.alex_movement_trigger2','off') %}
switch.telnet_alex_unsettled_none
{% endif %}
@snow zenith Rule #6: Spam will not be tolerated, including but not limited to: self-promotion, flooding, text walls (longer than 15 lines) and unapproved bots.
Please take the time now to review all of the rules and references in #rules.
you figured it out, you needed quotes around that last bit
me? yea i noticed i was mixing ' and " inpropperly
yup
not sure if it's a bug, but the template for a rest switch doesn't seem to track the on/off state when using
'{{ value_json.is_active }}'
but does work with
is_on_template: '{{ value_json["is_active"] }}'
and that's me returning via the rest api
return_data = {"is_active": "true"}
return return_data
Can someone take a look at see why this automation is kicking off errors in the logs? The automation still works, not sure why it's kicking errors. Error at the top, automation at the middle and the script the automation calls at the bottom. https://pastebin.com/QGnMLAg8
Easy 😉
(error is in the template, don't think this goes in #automations-archived but can move if so)
You have two templates neither of which have an {% else %}
If the action is hold then an empty brightness is sent
If the action is anything other than single/double/hold then an empty service is sent
Ok, I made some changes to my lighting automation for sleep/automatic because I have some roommates now. The whole idea is that each bedroom has a sleep and automatic mode. If one bedroom goes to sleep, only that bedroom does, if all 3 go to sleep then the whole house does. Now to make it more complicated, Im tracking if the roommates are home or not. So if one is not home that night, their bedroom would not be counted, and it would only require the other 2 rooms to go into sleep mode for the house to move into sleep.
Here is what I have. https://hasteb.in/ijepekal.php
Im having issues with the second value template. One of the 2 people is not home and the other is right now, and for some reason its still excluding their room. Where is my logic failing for this?
Do I need more coffee?
i think your or is goign to need () around both is_states
both is_states meaning the first 2
You probably just need to wrap your logic in parentheses to make it execute in the proper order
{% if is_state('device_tracker.jasons_iphone', 'home') or is_state('device_tracker.stevies_pixel', 'home') and is_state('input_select.front_bedroom_override', 'Sleep') %} right now it's condition or (condition and condition)
Do you mean like this?
https://hasteb.in/zecuyimo.php
That seemed to do the trick. Thanks guys
Evening guys. Could use your help with some automation templating....
@opal dawn posted a code wall, it is moved here --> https://paste.ubuntu.com/p/FTNrHfF4GB/
What are you trying to do with the templates? Ignore the code for now, what are the requirements?
From what you've shared, it looks like you're trying to do it only when it's before 6am and after 9pm. That's impossible.
Switch on something when a read out humidity is below 95 for 10 minutes between a certain setup time
Between what times?
should be after 21:00 and untill 06:00 in the next morning
Exactly. That's not what you've written.
You've said that you want it to be on only if it's currently before 06:00 and after 21:00.
Correcto
Today is Friday, right? It can't simultaneously be before 6am on Friday and after 9pm on Friday.
You're trying to do 'after 9pm Friday but before 6am of the next day'
@opal dawn 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.
So you want a template that checks for 'not between 6am and 9pm'.
Or is either before 6 am or after 9 pm
Your templates aren't the problem, your logic is.
indeed mono. 😄
I want to activate it after 9pm and until 6am next day, Thats makes it a bit complicated now you guys mention it
Not complicated. See Tinkerer's answer.
If the times are fixed, a time condition will do it
It's tempting to come up with a complex answer to a simple problem if you don't understand it clearly.
The times are fixed but based on input_datetime so therefore using the templating part.
So that if only changed one input_datetime all logics still works
I was hope to get a time window with the template a created it.
hope=hoping
You can... just make it 'or' instead of 'and'.
I need to let that one sink in
If it's 'before 6' or 'after 9', you want it to do the actions. But we're talking about #automations-archived here, not templates 😉
you right 😉 but I my second template part didnt give me the desired result heheh
Hi guys, I have a template binary_sensor that is showing as off, however, if I put the template into the template editor, it evaluates as true. I know this isn't a ton of info but I was hoping someone had an idea.
.share the sensor config
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
@buoyant pine I'll have to do this when I get home. Thanks!
I am fairly unfamiliar with templates, but I think this is the right place to ask.
I am trying to pull the Hours and Minutes from an input_datetime defined in my configuration as coffee_time and I am looking at the docs for it, but I am just not sure how to setup a template that pulls hours out as one sensor (I am going to feed this to another device) and minutes out as another. I think it has to look something like this:
input_datetime:
coffee_time:
name: Coffee Time
has_date: false
has_time: true
###
sensors:
ct_h1:
value_template: '{{ states.input_datetime.coffee_time.%h | int }}'
But I cannot get anything to work, nor could I find something close that I could modify until it worked.
You have double quotes around it instead of single quotes, is that important?
i have double on the outside because i'm using single on the inside
also, to explain, input_datetime entities have state attributes for hour, minute, etc.
Thanks! I read the docs like 5 times, and it says they do for dates, but doesn't call it out for time, so I thought only the %h and such were defined...
you can always look at developer tools > states
So anything that shows up there is accessible?
yeah
Thanks! let me restart and we will see what happens.
@buoyant pine here is the config for my binary_sensor:
I hope I did that correctly. I'm trying to accomplish a binary_sensor that is a condition for when to send a notification about motion in my garage. The condition being if the garage door is open (cover.garage_door), the door into the garage hasn;t been opened in 30 seconds (the second part) and an input_boolean is true.
scratch that... an input_boolean is false
Template sensors only update when the entities in them are updated, so if one of those other entities doesn't update at least 30 seconds after the laundry room door sensor changes state the template sensor will stay off
You could set up a time sensor and use that in the template sensor config
entity_id: sensor.time
``` which will force the template sensor to update every minute
I figured that was the issue. I'll do what I did with the input_boolean and create a timer in node_red
thanks for your help and clearing thst up for me!
Caught me just in time--I've been putting my phone on silent every Friday night starting at 19:30. Four minutes away 😄
@buoyant pine Hey, it worked like a champ! Thanks.
Not to wear out my welcome, but id like to ask an open ended question... Does it make sense to split my "helpers" out of my configuration file so I don't have to keep rebooting the whole system?
You can reload those at configuration > server controls regardless of where they're at in your config files
Same with everything you see there
I don't see them there
RELOAD LOCATION & CUSTOMIZATIONS
RELOAD GROUPS
RELOAD AUTOMATIONS
RELOAD SCRIPTS
RELOAD SCENES
RELOAD PERSONS
RELOAD ZONES
i have a question regarding template switches. here is a screenshot, i'm hoping to extract the value of hvac fan_mode=X to the switch.
currently template switch does not seem to pickup the fan is running, not sure why tbh.
link to the template switch snippet from my config
https://paste.ubuntu.com/p/HjNhdNDZPp/
What does the value_template that you have commented out render as?
I soldered a button to a contact sensor and now I have a binary_sensor I can physically toggle the lights with. I'd like to make it more complicated. I want to add an action for holding the button for 2 seconds. So one click toggles light A, and a click held for 2 seconds toggles light B.
Does anyone have an example template that does anything similar to this behavior that they don't mind sharing?
@hollow bramble i made a post if it helps
https://community.home-assistant.io/t/what-type-of-template-would-work-for-a-hvac-fan/210894
hey
i have created some 'sensors' in a new file sensors.yaml
i didn't have an sensors.yaml before
so i tryed to put it in the configuration.yaml file as
sensor: !include sensors.yaml
i did config test was all green so i restarted but nothing there in ha
i think the include don't work
Use the command line checker, not the one in the UI.
Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.
Good afternoon.
I flashed my TYMC-1 door sensor with tasmota and configured it according to a template from blakadder.
What I want to add to my HA yaml is the battery level but I don't know how exactly how to add this.
The topic is: stat/Door_Sensor/BATT and the payload can either be: high, medium or low.
Do I need to use a template for this or how to add the sensor in the yaml?
Well, first step is an MQTT #integrations-archived - either auto discovered, or manually configured
Tasmota supports auto-discovery though, so I'd start there
Okay thank you. I doubted between integrations and this channel
Is there somewhere that I can see a list of all the "magical" unit of measurements?
The units that will change the icons automatically and such
I think that's the device_class, and not the units
the units are just a string
device_class
(device_class)(Optional)
Sets the class of the device, changing the device state and icon that is displayed on the UI (see below). It does not set the unit_of_measurement.
"Defines the units of measurement of the sensor, if any. This will also influence the graphical presentation in the history visualization as a continuous value. Sensors with missing unit_of_measurement are showing as discrete values."
that's true, but you were asking about the icons
yeah, it affects icons and such too
you sure?
though undocumented there
let me test something to gaurantee
yeah, if I remove the unit_of_measurement from a temp card I have, it no longer has a thermometer icon
from a temperature template*
set it to some random value?
point being that I don't think there's any comparison being done
ok. make it "foo" and see what happens
interesting, I guess I'm wrong
oh well, I'll look through git to see if I can find anything fun. I was just wanting to use any "magic" where possible
thanks!
time to dig into the source
@inner mesa https://github.com/home-assistant/core/blob/63e55bff5233b975a1062ddbf14ef2450115e500/homeassistant/const.py#L353 if you get curious
thanks! was looking for where the translation from that to icon takes plae
yeah, let me know if you find it. I just wanted to make sure I was formatting my units the way they recognize them internally. If they change the icon, I'll see it. If not, I'll do it manually.
HA does do automatic temp conversion, so I wonder if it's special: https://community.home-assistant.io/t/configuration-template-how-to-convert-f-to-c-on-temperature/189003/34
I'm glad you brought it up because I didn't think it mattered at all
I have a pretty decent history of finding nuances with different software.
man, I just got HA. I love this thing.
I had an unused pi for months.
const unit = state.attributes.unit_of_measurement;
if (unit === UNIT_C || unit === UNIT_F) {
return "hass:thermometer";
}
return domainIcon("sensor");
defaults are at the top based on device_class, and there are a few special cases like that
boom
so it seems
thanks, I'll test it in a moment
yep, @inner mesa I'm getting magic with both the device_class and the units
thanks
I need to find a way to make lovelace rebuild when I edit includes
touch ui_lovelace.yaml
yeah :/
I have only been on HA for two days but a few hours ago I broke everything into clean individual files
it makes it a lot easier for me to manage, even if I have to save lovelace yaml
nice!
I did that for my views, but then ended up sticking my main view in ui-lovelace.yaml to avoid annoyance
also keep in mind that if you use anchors, they don't work across includes
yeah, not using any anchors atm
that's another annoyance. otherwise, I'd have an include file with my anchors
what are you using yours for?
ahh, I haven't installed that yet
I installed card tools and the secondary info mod
well I random one I found on a PR that supports the same formatting
custom cards like button_card avoid the need for card_mod, but not for everything
anyway, somebody will be along shortly to tell us to move to #frontend-archived
lol
The fact that you can go look up the source to answer questions like this is a big reason to stick with HA. Good luck
oh, I found a bunch more
I didn't realize the one you linked me was only for sensor and there are others for binary_sensor
Hey guys, i am trying to conceptualize how I would template to return the calendar days between two events. Of course I can simply subtract the timestamps from one another and divide by 86400, but that returns 'days' meaning 24 hour periods. I want to return how many actual days, so if the current time is 11pm on Sunday and the second event is either 2am or 11pm on Tuesday, it would return 2 days. Having trouble envisioning how I would do this. Any ideas appreciated!
(for context, my goal here is to compare the current date to a date in a google calendar and be able to return if the event is 'today' 'tomorrow' or 'the day after tomorrow' or 'in X days')
@violet oyster extract the day from the timestamps and find the difference between those
would that work across different weeks? like if today is saturday would tuesday show +2 or -5
or do you mean date
Date, yeah
ok good idea. ill give it a shot
Like, 25 - 23
even then i wonder if it would work across months
every way i think about it i hit a roadblock lol
Well, you could still find the difference in seconds and use templating to determine the number of days based on that
thats how i have it now. round(0) filter to find days
it almost seems like there would have to be some element which would understand context. or im just wrong and its something simple i am not seeing
@violet oyster Take your current day timestamp and set the timestamp to midnight, then do the calculation.
if the result is less than 24 hours, today. Greater than 24 but less than 48, tomorrow. Greater than 48 but less than 72, day after tomorrow. else x days.
{% set midnight = now().replace(hour=0, minute=0, second=0, microsecond=0).timestamp() %}
{% set event = states('calendar.xxx') | as_timestamp %}
{% set delta = ((event - midnight) // 86400) | int %}
{% if delta == 0 %}
Today
{% elif delta == 1 %}
Tomorrow
{% elif delta == 2 %}
Day After Tomorrow
{% else %}
In {{ delta }} Days
{% endif %}
You'll probably need to edit the {% event = states() %} line to grab the datetime object / timestamp properly. That's just a placeholder.
@violet oyster also made a topic on the forums for support. https://community.home-assistant.io/t/days-away-from-calendar-date-template-guide/211209
Hello, i control LED over MQTT. In tuya application i can choose if i want use RGB or white led. How can i do this on HA? This is my config: https://pastebin.com/u2QCLU4u
@mighty ledge Thank you!!!!!
Hello All, is there a way i can pass parameters to a template? I need to create 5 template sensors which share the same "templating code" but the output depends on the state of another 5 sensors. So ideally i wanted to have the ability to create `template_sensor_1: which reads from raw_sensor_1" , "template_sensor_2, which reads from raw_sensor_2" etc.
why not just copy and paste to make the extra template sensors?
cause it's a very long template. and maintaining it could be a pain.
i cant think of a way to do that without writing a python script or something
You can't "template" template sensors I'm afraid
you couldnt create 5 entities from one sensort
You could use YAML anchors
YAML has a handy feature called anchors, which let you easily duplicate content across your document
ha i did not know that existed
i knew there was a reason to get out of bed today. just didnt know what it was until now.
Yes but with anchors i am pretty sure i cannot anchor in the middle of a template @arctic sorrel
maybe i can use the include jinja2 functionality?
You can define a variable before the anchor though, and use that variable
@gray wharf just use vscode and you can maintain/adjust the sensors using search & replace. i have several similar setups and it really isnt that bad
That is true @violet oyster but not being able to reuse a template which is 15 lines of code makes me cry :)
@arctic sorrel ???
so you think this is possible?
data_template: >
{% set myvar = 0 %}
&hey
yo
and then reuse like so?
{% set myvar = 1 %}
<<: *hey
?
hmm i will try but my gutt says no 🙂
@gray wharf you should see my config. youd cry a river
Fortunately we're not listening to your gut 😉
nope @arctic sorrel not working.
20K lines here 😉
It's possible the issue is with the way you're doing the templating, but the anchors have to be in the same file
how many commented out lol
You can't anchor over multiple files
8 lines here
theyr're in the same file.
lol
This does "something"
i gotta clean my shit up. so many useless projects i no longer use and didnt want to delete out of sentimentality
i do enjoy going back over my profanity ridden comments i added in frustration before I knew what I was doing
hello guys, Im new around here, looking for some help on a template im trying to figure out. Please bear with me im not a programer and all this templating really exceeds my level of confort:
I have this piece of code that works:
Not sure how to paste it in the chat 😅

😀
Which template are you having trouble with? There are several there
ok, so my problem is if ON time is later than OFF time
that code doesnt cover that scenario
not sure how to work around it
lets say switch on 23:00 and off 02:00
first I would check the inputs against each other to figure out which one is earliest
not sure I get what you mean
{% if states('input_datetime.room03_ac_timer_on').rsplit(':',1)[0] < states('input_datetime.room03_ac_timer_off').rsplit(':',1)[0] %}
ok
@lapis quarry check the logic, but this should make it more readable and easy to manipulate https://hastebin.com/oqowoxikik.php
Oh oops, I forgot to change the logic between the two, but hopefully you see the idea
yes I think that makes sense
awesome, let me tinker with it I will let you know if I can get it to work 😄
also your condition templates can be simplified
You don't need to if to return a boolean
{{ states('input_datetime.room03_ac_timer_off').rsplit(':',1)[0] == states('sensor.time') }}
interesting, thanks for the tip, should have came to this chat earlier, been trying to figure all this crap out for months with limited sucess, normally get things to work but takes a lot of guessing
🤣
Luckily the dev tools template editor makes the "guessing" method very easy
I mean for doing it all on your own you got 99% of the way there. That's very impressive
You just described almost any modern programming job
LOL
well actually the whole system is pretty complex by now, been a year working on it 🙂
Oh oops, I forgot to change the logic between the two, but hopefully you see the idea
@hollow bramble Amazing that did the trick 😄
thanks so much
and now you know where to find us for further assistance 👍
yes actually I need to repeat this code 20 times
Its a 20 room building, and im finding my self repeating the code everywhere, there must be a way to rehuse code, that is something I need to figure out
would be extremelly usefull
any sugestions?
YAML anchors if everything is within the same file
I try to organize one file for automation, for instance I have a file where I would have this same automation repeated 20 times
that is how I have structured everything until now
you can simplify it a bit reduce lines too:
{% if timer_on < timer_off %}
switch.turn_{{ 'on' if timer_on <= current_time and timer_off > current_time else 'off' }}
{% endif %}
"simplify" 😱
@lapis quarry might want to make an exception for this. YAML anchors could be a big help here
You could also get clever with the template, but it could get really complicated really quickly
@lapis quarry might want to make an exception for this. YAML anchors could be a big help here
@buoyant pine What is that about
you can reuse that service_template with an anchor/alias combo instead of copying and pasting it 20 times. that will also allow you to update the template once if you need to make changes instead of 20 times
but again, everything needs to be in the same file for this to work
everything?
everything that uses this same template
any automations that you want to use the anchor/alias with, rather.
The way I ahve it is I have a file with the 20x input_datetime.roomXX, another file with the 20 switches, etc..
packages
wait, that doesn't matter. i'm just talking about the automations
are all 20 automations in the same file?
yes, that would be the idea have the 20 in the same file but that I dont have to write 20 times the same thing
right, so anchors/aliases would work for you then
It would be awesome for maintenance and future upgrades, its a nightmare to mantain and modify now
😭
anchors and aliases
https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/
@buoyant pine ok but this sounds chineese to me
jaja
here's an example from my setup: https://paste.ubuntu.com/p/JtHHqtfp3v/
i want to use the same data in color_name in both service calls, so i made color_name an anchor with &color and referenced it for value: at the bottom with *color
so when home assistant reads that file, it sees this: https://paste.ubuntu.com/p/2KKNTn3cK6/
I see

yes that seemed to work
What I was hoping was more like how it could be done in a way I can define somewhere for example I need 20 instances and it would automatically generate them, (need to deploy this in diferent locations that will have different amount of rooms, the automations and functionality is the same every time but I need to adjust the code for the number of instances needed everytime, the way im handling now it is just having all the automations created in background and just not displaying the ones that are not used in the frontend
hey
its not very elegant solution and a waist of resources
but its the best I could come up with to make it managable and scalable
not sure if what im saying is even possible
i want to use white_value_scale in light mqtt template, but white_value_scale is not supported on template. How can i scale this? My max white_value is 1000, and ha max is 255. Now i have this: {{ white_value * (1000/255)}}
waste
@quiet kite share the config for the mqtt light
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
@buoyant pine https://paste.ubuntu.com/p/4NdmsDhG3g/
good lord
😭
need to get some rest, 1 am here, will be back tomorow, thanks for all the help guys much apreciated 😄
i'm not saying it's wrong, i was just overwhelmed by the number of lines lol
I think so
But i must write few additionals lines, for example support for getting colour state...
the math looks fine, but you might need to convert white_value to a float and then the result to an int
So isnt simplest method to scale?
, "22": {{ (white_value|float * (1000/255))|int}} ?
looks fine, but i don't know for sure if you can use templates there
works, so i thinks that is good
i have few this controller drivers, can i make any template from this, and give only state_topic, command_topic, and name?
or not a template but function or method
good morning guys, is it a normal behavior that the value_template triggers when the sensor goes to unavailable?
'{{ states.sensor.canon_ts5000_series_magenta.state | int < 15 }}'
Surprised it doesn't throw an exception
But in jinja2 if a non numeric string is cast to an int it gets set to 0
Tl;dr that's normal
i solved it like this: {{ states('sensor.canon_ts5000_series_magenta') != 'unavailable' but it's additional code 😕
hi all, I'm trying to write a template that checks if the state of an entity has been in that state for 2 hours. Is this possible with the templating engine, or do I need to resort to a condition automation
What are you trying to do?
I have a message that I want to send if the state of my garage door has been closed for 2 hours
State trigger with for: '02:00:00'
{% if is_state('cover.garagedoor', 'closed')%} will check if its closed, but how to check if it's been closed for x period of time?
can an automation have 2 triggers?
No need for a template here
right now i have it on a time trigger on certain days
Yeah you can have multiple triggers, conditions, and actions in an automation, but let's go to #automations-archived
ok
hey
i have sonoff mini with installed esphome. I add this ESP to HA by using webUI in HA. How can i add esphome on yaml configuration?
https://www.home-assistant.io/integrations/esphome says UI only
I cannot belive to this.
Why?
because configuration by UI isnt easy to move or copy or share
In Home Assistant? That's #automations-archived
In ESPHome, that'd be a thing to ask on their Discord
ok, thanks
as can be shown in this screen shot: the top text says both doors are open but they clearly arent as shown below: https://i.imgur.com/JYnFlTl.png
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)
Test your template, make sure it works
this is the code ``` rules: >
{% if states('binary_sensor.back_door') %} <li>Back Door is
Open</li>{% endif %}
{% if states('binary_sensor.side_door') %} <li>Side Door is
Open</li>{% endif %}```
oh nice ive never tried the template dev tools yet
the test says is true no matter what the status of the door is
is there a way to have it tell me what the states are?
i tested like this {% if states('binary_sensor.back_door') %}true{%endif%}
then open and closed the door and it stayed true
If only we had templating documentation...
{% if is_state('binary_sensor.back_door','on') %} <li>Back Door is
Open</li>{% endif %}
oh i just copy paste what mono gave me so i just assumed it was correct
I can't template, don't trust me 😄
lol ok i will keep it in mind! 🙂
Trust but verify
ah ok this is where all the good info is: https://www.home-assistant.io/docs/configuration/templating/ i was looking at the first link
based on what these docs say shouldnt this show me the states in the template tester? {{ states('binary_sensor.side_door') }}
or can you not use the template test in that way?
oh nvm its working now, it just says off
Which would be correct
i thought it would print all the available states
No
how would i go about finding the possible states of an entity? i know its not needed in this case
Other than for things that are binary there's an infinite number of available states
ah ok
i didnt think a door would be on/off though, i thought open/close or maybe true/false, good to know that binary is always on/off
Well, yes
That's explained in the fine manual
And also easily seen by looking in
-> States
oh very nice thanks
this looks a lot like twig
i guess they use the same base schema or something
or maybe they are both forks of the same thing or something
They're both templating engines. They're all trying to do the same thing.
Did you test the template in the templates dev tool? And did you check that the entity/attribute actually exist?
You see that sensor in states?
well you're trying to create a sensor with the same entity_id as an already existing sensor, that might be part of the problem
Is there a way I can put a phone on vibrate in a template?
Well, if there's an integration that supports it, then yes
So basically when you tell Google Assistant goodmorning or goodnight, it can control those things, but not when you use a Google Home to do that. I want to use Google Home
Templates are just ways of allowing your automations and scripts to be flexible
Maybe I should ask there then, thanks
With scissors?
The actual answer will depend on context... 😉 What data you're working with, what you're looking to extract, etc etc etc
Photo... of text 🤔
-> States @naive plinth - find the entity and copy and paste the attributes. Remember to use code markup 😉
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
how can I cut out the values I need? I have sensor ups with state: Bus Voltage: 5.092 VBus Current: 1224.878 mAPower: 6241.951 mWShunt voltage: 61.710 mV
Please use imgur or other image sharing web sites, and share the link here.
- platform: template
sensors:
any_window_open:
friendly_name: Janelas
device_class: opening
value_template: >
{{ states.binary_sensor.dw_varanda_sala_contact.state or
states.binary_sensor.dw_varanda_cozinha_contact.state or
states.binary_sensor.dw_janela_wc_rc_contact.state or
states.binary_sensor.dw_janela_lavandaria_contact.state}}
why this binary sensor template always get CLOSED
if all sensores are OPENED?
and if I test in tempates I got ON
in dev tools»template
Why not just use a group?
This sensor I want to be "ON" if some of this sensors are "ON"
err... cause I never thought of that....
I'm lazy...
I thought this was the best way to do it...
Well, if you want the changing icon it is
I don't have that idea of you... 🙂
yes I want to have a badge with the icon changing
I'd also swap states.binary_sensor.dw_varanda_sala_contact.state for states('binary_sensor.dw_varanda_sala_contact') (etc)
will do
But, what you're wanting to do is see if they're on
so really you want is_state('binary_sensor.dw_varanda_sala_contact','on') etc
with the first option it got the same result...
Yup 😉
let's try the 2nd
That first option simply returns the current state
Given that the state is on and not true or false...
{{ is_state('binary_sensor.dw_varanda_sala_contact','on') or
is_state('binary_sensor.dw_varanda_cozinha_contact','on') or
is_state('binary_sensor.dw_janela_wc_rc_contact','on') or
is_state('binary_sensor.dw_janela_lavandaria_contact','on') }}```
same result...
wait
it did not have finished starting...
👍
working
thanks
for this, and the great job and contribution for HA
if I want the badge to change the color is it possible?
That's a thing handled in the #frontend-archived - check the card options
yeah...
Hello everyone! Sorry to bother but I am trying to create an entity out of a device property with this template :
- platform: template
sensors:
front_deadbolt_status:
friendly_name: "Front Deadbolt Status"
value_template: '{{ states.lock.porte_appartement.attributes.notification }}'
What's the problem?
Sorry for no code formating. 😅
You can format 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
Unfortunately it does not appear in HA 0.112.4
Where did you add it? And did you run the config checker?
In the config file I have a reference to a sensor file which contain some configs. (they do work) but the above code seem's dead.
Yes, the config checker is happy.
No errors in your log after restart?
I was hoping for. I did several restarts to see if it would output there but nothing. 😦 Usually that's how I fix my problems.
Where are you looking for the sensor?
In the entities.
look in dev tools > states
I did it but no luck 😦
Which config check did you do? You should always do the command line one.
Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.
UI.
Neat! Let me do this! 🙂
The config checker exited with no output. Is that normal?
that means the config is okay
Oh okay sorry about that. 😅
One last thing to check here since it's sounding more and more like an #integrations-archived question. What does the template show if you put it into
> Templates?
That's what I did initially and it show me this : https://i.postimg.cc/PJJfQKRj/image.png
Just the template part, not the whole sensor config.
The bit in {{}} without quotes.
Apart from sharing text as images, yes 😉
Well the template is fine... so you should head over to #integrations-archived to figure out why the sensor isn't working.
Alright then! 🙂 Thank you so much for that speedy help! 🚤
shouldn't this work?
- service: mqtt.publish
data_template:
topic: 'bulb/cmnd/backlog'
payload: {{ states('variable.bulb_backlog') }}
as long as I first set variable like this:
variable:
bulb_backlog:
value: 'color 000000FF; pulsetime 400'
Yeah I got it. I forgot the "" around the template.
now it's payload: "{{ states('variable.bulb_backlog') }}" and it works.
@cedar chasm posted a code wall, it is moved here --> https://paste.ubuntu.com/p/N5cPvgvRdP/
@cedar chasm posted a code wall, it is moved here --> https://paste.ubuntu.com/p/Wbq6Bjq5dC/
Thanks for your help!!!
@cedar chasm posted a code wall, it is moved here --> https://paste.ubuntu.com/p/p2hhJ6ZQ7y/
@cedar chasm Rule #6: Spam will not be tolerated, including but not limited to: self-promotion, flooding, text walls (longer than 15 lines) and unapproved bots.
Please take the time now to review all of the rules and references in #rules.
Hello
is there a way to read "states.sensor.salone_temperatura.last_updated" in javascript
@rugged laurel My text is that long. Wasn't able to make it shorter to explain my problem
on the lovelace UI?
In JavaScript? That would be a custom cards thing, ask in #frontend-archived
Alternatively, you could make a template sensor, which is an #integrations-archived thing
taken from the same database. In influxdb and grafana i'll get my outside temp
I want to use that database entry as a ha influxdb sensor
Why are you channel hopping?
sorry, was wrong. deleted
Hello, I'm having a small problem with a template sensor. It wont update to the correct value unless I reboot.
- platform: template
sensors:
anyone_home:
friendly_name: Anyone Home
value_template: "{{ states.person | selectattr('state','eq','home') | list | count > 0 }}"
This in my 'sensors.yaml' file.
This works as expected when using the template setion the the Dev tools
I also have other template sensors in the same section that work fine... What am I missing?
Because, it doesn't have any entities so it doesn't update
ah, so theres no way to just have it use all 'Persons'?
Not unless you list them, or give it some other entity it can use to update
You could force it with a date time sensor that updates every minute
Is there a reason you're not just using the state of a group that contains all the persons?
That's the built-in way to check if anyone/someone/everyone is home.
(depending on how you configure it)
I see, so the entity being listed is what acts as a triger to update...
mono, only reason is having it this way, it never needs to be changed when adding a new person, it it will just feed off all people listed in the persons section
Which would be great if it was designed to work that way 🤷♂️
it will work like that i think with with the time entity as per @arctic sorrel's suggestion
Sure. It's still just a hack though.
And depending on what you're trying to do with it, there may be better options. If it's only for frontend, some cards will do the wildcarding/filtering for you. If it's for automations, a sensor is your only option.
Yes its for automations... for example lights on in evening will trigger in node red, if no one is home then it will wait for someone arriving and then perform the action
based on the one sensor value
rather than having multiple triggers.. I find it easier in terms of maintanence because theres not enough hours in the day 😑
Realistically, how often are you adding a person to your system?
Its because I add guests, so that automations trigger just the same way based on their presence
No guest mode? 😮
Everything hangs off that one sensor for presence rather than multiple
I have a guest mode, that wont serve the same purpose of lights turning on autmatically if they arrive homw while no one is in
Adding guests as persons is... more work than I would be willing to do
It's your home, so do what suits you. I just imagine a 'guest mode' as 'make my house dumb for a while so they know how to work it'
Expecting guests to have a device tracker? Pass.
I get a telegram notification of a new phone mac connecting to wifi, its just adding that, which is only a one time thing, then link to a person..... then when/if they choose to revisit, then I don't have to anything...
Heh, wifi device trackers. Yikes
Unifi has been solid for tracking based on wifi for me.
Yeah I use unifi for some limited device tracking, seems to work well
Bluetooth tracking FTW 😛
I'm too lazy to set up monitor
hi.
I've been told what I wanted to do could be achieved with a template. I have zigbee wall switch that I connected to nothing, and a fan with a light which can only be operated by an IR remote, but also have wifi config (haiku). I'd like to configure so that if i turn on this switch then it will turn on the fan; same for off ; but I also want to have the fan drive that switch (so the light on the switch matches the status of the fan)
The XY problem is asking about your attempted solution rather than your actual problem. This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.
The problem occurs when people get stuck on what they believe is the solution and are unable to step back and explain the issue in full.
It might be that a light.group is what you're after, or a Zigbee group, or ...
hmm, with a light group it doesn't appear that change the state of the member of the group will make the other members copy that state
No, but ... you're explaining your solution, not your problem 😉
With a light group you can turn on/off the group
I don't believe I did
I described the setup I have, and what I want to achieve
I can achieve what I want be setting two automatiion rules
one using two triggers (either item being turned on) ; which will then set the state of both entities to on
and another automation rules doing exactly the same but for off
surely, there's a better way
You can do it with templates, to match the state of the trigger entity
https://www.home-assistant.io/docs/automation/templating/
https://www.home-assistant.io/docs/configuration/templating/
you said automation templates, but this gave me no useful result when I searched
Automations are how things happen in HA - how it reacts
Templates are how you make those flexible
and I don't see how this makes it any easier to my current solution of having two rules
One, more complicated one
Easier... not necessarily, but you said you wanted to do it without two
I had hoped it was something obvious I had missed
smartthings has a mode doing just that, to emulate a 2-way light switch
HA doesn't natively do that
On the other hand, the automation and templating engine is powerful enough you can do it yourself
My only warning with using automations to do this would be: consider the timings.
hmm. it's annoying that I can no longer create automation rules via the UI, just because I added an automation entry in configuration.yaml to manage zigbee2mqtt
I have 2 pairs of lights that I want to keep in sync. Any delay in communication meant they could get stuck in a permanent on/off loop if the messages crossed.
I personally keep all my manual automations out of automations.yaml, but you can mix them in there if you want to
I have 2 pairs of lights that I want to keep in sync. Any delay in communication meant they could get stuck in a permanent on/off loop if the messages crossed.
@ivory delta I've never had this happening so far; and that was using those switches via smartthings which has a pretty high latency
@arctic sorrel where do you keep them?
do you do something similar to the script: and input_text: entries?
No
I don't create any input_X entities in the UI, and script I don't use the UI editor for
Not that I use the UI editor for automations either really
those files are to be saved in the same folder?
any of those
"Helpers" go directly to storage, and aren't in YAML
It took... some time to get right
i can imagine
You said 30 minutes 😮
30 minutes... at a time 😄
i draw something with a tool going over some old floorplan I had on paper
looks shit really 🙂
I used Inkscape and layers
All the base shapes are rectangles, lined up very carefully at maximum zoom
@arctic sorrel do you have the automation rules described in the z2m doc? the one allowing to rename a device, remove it etc? if so, in which file would that be?
I don't, only one I've got is for joining
reason I ask is I wonder how I convert the stuff I have in the main configuration.yaml to one in a sub file
looking at your repo; they don't have some entries in there
well, not quite, it doesn't have the same indentation nor automations.
hmm, keep getting errors about expecting keys
Well, indentation changes because it's included at that level
So, each included file starts at zero
Man I am so confused...I don't understand why "value_template" is required when defining a switch...is it used to make sure that the device is on?
That being said, I am trying to use one switch to adjust the thermostats of 2 different devices, how do I include both devices in the value_template state check?
I feel my syntax is probably off, or is the double && right?
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
It’s required so it knows what to call based on the current state for toggle
Show us the whole switch definition please 😉
@amber night posted a code wall, it is moved here --> https://paste.ubuntu.com/p/5b3h9ZmcgX/
I haven't tested it yet just wrote it and I feel that value_template is wrong though ^
@mighty ledge thank you that does make sense, so I do need to include both state checks
@amber night Rule #6: Spam will not be tolerated, including but not limited to: self-promotion, flooding, text walls (longer than 15 lines) and unapproved bots.
Please take the time now to review all of the rules and references in #rules.
You need whatever logic works for you 😉
If the switch is on when both are on, then yes
&& doesn't work. and
this ain't bash
Or <insert 99% of programming languages here>
thank you, and I'm unsure if "and" is the right way to code this or not but I will try it out and see how it acts
thanks for the syntax for that
@amber night the language is Jinja2
it's almost identical to python but it has these things called filters
I guess I could do "or" in case the power is out on one of the thermostats and the switch would still work?
Jinja Template Designer Documentation
For more examples and samples, visit see this page
Jinja has a lot of similarities to python in syntax
OIC thank you
in some cases you use python syntax directly
Well, that's just home assistants version of it. Jinja itself does not have those python calls.
ah ok im sort of a a shitter, i know c/c++ and so i translate things from that hehe
thanks yall im sure ill be back with more questions
good news then, you don't have to manage memory
🙂
how can I cut out the values I need? I have sensor.ups with state: ”Bus Voltage: 5.092 VBus Current: 1224.878 mAPower: 6241.951 mWShunt voltage: 61.710 mV”
I need get bus voltage
That whole string is the state? Where does it come from?
@naive plinth {{ states('sensor.ups')|regex_findall_index('Bus Voltage: ([0-9.]+) V') }}
Thx
@dull bloom posted a code wall, it is moved here --> https://paste.ubuntu.com/p/WRWtfKnqGV/
@dull bloom Rule #6: Spam will not be tolerated, including but not limited to: self-promotion, flooding, text walls (longer than 15 lines) and unapproved bots.
Please take the time now to review all of the rules and references in #rules.
And no, that won't update, for all the reasons warned in the templating docs 😉
forgive me... I'm new to templates and learning as I go
can I do it in a function node in node red? I really just want to output the value to my echo dot as a TTS anyway
I don't see the warnings to which you refer
Your template updates when input_boolean.leia_pooped updates
But, you do realise most cards can display that information without this 😉
that's what I was afraid of... I need to dynamically calculate the time between the last update and now... so my alexa can say "it happened 2 hours ago" -- I'm thinking a function node in node red is probably the way to go
You can do it in a template, but exclude it from history/recorder if you do that
I'm setting up an alexa routine so I can ask alexa when was the last time and she can tell me "it was xx minutes/hours" ago
ugh... so much to learn
The price of great power flexibility 😉
I'm taking a break... been at this all day... eyes are crossing
Hi,
I require syntax help
I want to divide a valve by 100 of a sensor
value_template: "{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') }}"
It's basically just high school maths, with a tiny twist that templates produce strings, so you need to turn them into numbers again
@arctic sorrel I understand its basic maths, just can't get the syntax right.
Thanks will try the examples thanks.
@calm tinsel value_template: "{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | float / 100 }}"
Pffft, I was trying to teach him to fish...
🤣
| float is foreign to everyone who doesn't code
tbh we kinda handle it poorly in HA
Yeah, stuff like that it should just convert it anyway
It might actually be a float because it's an attribute
but, that depends on the integration
You probably want to round it off too
maybe some day we will have a system in place for strongly typing crap
I'd like a system that just goes oh, you want to treat that like a number, sure
@mighty ledge thanks.. I had tried this before but got value of 0.0 which isn't correct.
@arctic sorrel All this coding is foreign to me 🙂
It won't take long to get the basics
Could it be that the attribute isn't seen as a number for some reason...
value_template: "{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') }}" gives me this value "1536" other numeric values aren't in ""
value_template: "{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | float / 100 }}" gives me 0.0
Order of operations, methinks.
What does
{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | float }}
``` show?
0.0
I suspect the attribute has the quotes as part of the value
Saw this with somebody the other day
yes it does
battery: 100
trigTime: "1595014489061"
temperature: "1537"
humidity: "3091"
|replace('"', '')
Not replace('"', '')?
{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | replace('"','') }}
yeah
thanks
Tried a few things... it really doesn't like that
I tried
value_template: "{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | replace('"','') }}"
value_template: '{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | replace('"','') }}'
value_template: {{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | replace('"','') }}
value_template: >- {{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | replace('"','') }}
try this
No luck
@daring musk getting late here.. I will try again in the morning.
Cheers to all that helped.
@calm tinsel
value_template: >
{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | replace('"','') }}
I do not know why I am so confused by "value_template" in a switch template...the status of my thermostat reads "auto" and my switch is made to change the target_temp_low and high...should my value_template be checking the temperature values of the thermostat and not the status of the thermostat?
I think what I'm looking for is input_boolean ok, ok makin progress
@amber night what is the template switch for?
to change the temperature range of two ac thermostats back and forth between 2 sets of values, looks like it's working finally! able to read a virtual status now!
Evening...
So been trying all day, got code that HA accepts but doesn't remove the ''
value_template: "{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature'| replace('"',' ')) }}"
value_template: "{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature'| replace('*"',' ')) }}"
any other idea's?
I'm fairly sure the pipe doesn't go inside the call to state_attr.
Keep the first but add a ) after 'temperature'
And then remove the extra closing parenthesis
@ivory delta thank you
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
New to jinja... is there a way to map over a list of states and reduce it to a boolean value? for example, in JS: states.filter(s => s.entity_id.indexOf('people') == 0 && s.state == 'home').length > 0
This seems to work {{ states.person | selectattr('entity_id') | selectattr('state', 'eq', 'home') | list | length > 0 }}
It might not update though
alias: volume up
sequence:
- data_template: {}
volume_level: '{{ states.media_player.upstairs_lounge_main.attributes.volume_level + 5 }}'
entity_id: media_player.upstairs_lounge_main
service: media_player.volume_set ```
im trying to get this working but keep getting an error @plucky token volume level
okay will try
volume:
alias: volume up
sequence:
- data_template:
volume_level: '{{ states.media_player.upstairs_lounge_main.attributes.volume_level + 5 }}'
entity_id: media_player.upstairs_lounge_main
service: media_player.volume_set
required key not provided @ data['volume_level']
its like its not recognising the data_template command
alias: volume up
sequence:
- data_template:
volume_level: '{{ states.media_player.upstairs_lounge_main.attributes.volume_level + 5 }}'
entity_id: media_player.upstairs_lounge_main
service: media_player.volume_set ```
value must be at most 1 for dictionary value @ data['volume_level']
Yes, I believe volume is from 0.0 to 1.0.
You should search the community forum. I think this has been done about, um, 1,000,000 times. 😉
yeah i did lol and for me i just get errors have everything else working for my media devices in the house except this dam volume issue .
anyway will keep searching
@candid iron Why don't you just use the media_player.volume_up service?
let me try
I think it just accepts an entity_id parameter, and increments the volume by 0.1, up to, but not exceeding, 1.0.
i tried this and get the data error data: volume_level: 0.05 entity_id: media_player.upstairs_lounge_main service: media_player.volume_up
Rule 1 of templating
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)
do you need to create a template yaml file to reference a template or does home assistant just recognise the syntax ?
Hello!!! I have a question
I understand how the tamplates works and how use them, just like programing with variabes and macros, but....
the part I don't get it is where to put them in Home Assistant for use them
Sorry, got trigger happy
if change the same sensor name, or have to create a new one or how it works
Some integrations support templates in their configuration. The docs for that integration will indicate if they do
If some one can guide me eater with a video or a page well explain it, or here, thanks I appreciate it!!
ok, what I want to do now is octoprint send the "time elapse" in seconds, I want to show them in DD:hh:mm:ss
{{ sensor.ender3_time_elapsed//84400 }}d {{ sensor.ender3_time_elapsed % 84400 // 3600 }}:{{ sensor.ender3_time_elapsed % 3600 // 60 }}:{{ sensor.ender3_time_elapsed % 3600 % 60 }} ```
but, I don't know where to put it on
is somebody here?
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?
Wondering, why is I enter this, the template works:
friendly_name: "Ender3 Actual Bed Temp"
unit_of_measurement: "°C"
value_template: >-
{{ ((states("sensor.e3d_actual_bed_temp")|int() -32) / 1.8) | round(1) }} C
but if I enter it with out the last "C", doesn't work,
friendly_name: "Ender3 Actual Bed Temp"
unit_of_measurement: "°C"
value_template: >-
{{ ((states("sensor.e3d_actual_bed_temp")|int() -32) / 1.8) | round(1) }}
why????
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)
Does it work when you test it?
The value shouldn't have C in it, since it's already covered by unit_of_measurement
yes, I just did with and with out
yes, that's why I am removing the C, but as soon I remove it, don't apply the formula and shows me in F
like should show 0 C, and show me 32 F
Ah... your system is using Imperial units...
yes
ender3_actual_bed_temp:
friendly_name: "Ender3 Actual Bed Temp"
unit_of_measurement: "°C"
value_template: >-
{{ ((states("sensor.e3d_actual_bed_temp")|int() -32) / 1.8) | round(1) }} C
ender3_actual_tool0_temp:
friendly_name: "Ender3 Actual Hotend Temp"
unit_of_measurement: "°C"
value_template: >-
{{ ((states("sensor.e3d_actual_tool0_temp")|int() -32) / 1.8) | round(1) }}
this ones top, show me the value in C, bottom in F
ok, So, What should I do to make it work?
Well... depends on what you want
If you go with the first, you have a string. If you go with the second, you have a number that HA auto-converts to your system's units
I want shows in C, because the 3d printer is the values always use
Then you need the first, the string
I want use a number, but in C
then convert your whole system to C
These are your choices
There is no magic third option
🤷
hoo, I thugh HA can do a conversion just with unit of measurement
@candid iron limit
- service: media_player.volume_set
data_template:
entity_id: media_player.upstairs_lounge_main
volume_level: >
{{ volume + 0.05 if volume + 0.1 <= 1.0 else 1.0 }}
Hello everyone!
I'm trying to move away from a setup where I have an input_select and an automation that selects the next entry thanks to some triggers.
I use this input_select to keep track of the state of the day (Morning, Lunch, Afternoon, Evening, Bedtime, Night).
So I thought about using a template sensor.
The template I've written is this one: https://github.com/eliseomartelli/ParentsHomeAutomation/issues/9#issuecomment-660546090
I've not yet implemented this since I'm not working with entities so I'm not sure if the "now()" will be rendered.
Documentation I'm referring to:
https://www.home-assistant.io/integrations/template/#working-without-entities
If I'm understanding it correctly I should move to a sensor based template with something like "sensor.date"
Hi, how can I in the script set if statement?
I want only if spotify is not in the state playing to call script below spotcast.start
you can use a condition before the service @sonic nimbus
You don't put if statements in scripts. Scripts are a linear sequence of actions.
If a condition fails, it won't continue.
if I put condition to whole script, first two services wont trigger

You could put a condition before the last service call so that if the condition is not met the script doesn't continue
- service.one
- service.two
- condition
- service.three```
really? 🙂 I didnt know that! thanks!
You are correct @ripe snow that should be a template sensor where you specify a entity_id that regularry updates
Thanks @rugged laurel!
LTNS ahaha
Yeah, it's been a while since I saw you on these parts
Been very busy with life in general, I don't wanna go off-topic, tho @rugged laurel
Hi everyone! Is there a way to force update an template sensor? It's available for REST sensors but not for template sensors. It needs to write the curr state even though the value isn't changed.
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
Show us the sensor, using a code share site 😉
(Yes, you can, but... probably the template is "wrong")
Well, the indenting is a train wreck, but it should auto update when any of those entities update
That said, looks like you want https://www.home-assistant.io/integrations/min_max/
The problem is; the values of the temp sensors won't update that much.. so this template sensor only 'updates' the value when one of the temp sensors changes. So i have in some cases 2/3 points in my graph per hour
Yes i already tried that.. but it doesn't update, tried it on the template sensor as well on the temp sensors
Well, if the value doesn't change, the state won't change
That's correct, but when you use force_update for example on a REST sensor, it does actually.
That's likely because other things change too, attributes etc
I don't think it changes the state, since the value is the same. It just means you can plot extra points on graphs, for example.
Automations won't trigger if it goes 'from' 7 'to' 7, since it was always 7.
Yes, that's exactly what i want to achieve..
Cool... but that's not the same thing as the state changing.
I've updated my template to this: https://github.com/eliseomartelli/ParentsHomeAutomation/blob/master/homeassistant/entities/sensors/sistema/stato_del_giorno.yaml
LGTM but maybe a second pair of eyes can spot something wrong with it 😉
yes you're right, so there isn't a way to get more points for plotting with a template sensor if the actual state isn't changing?
If the attributes change, maybe
@sonic nimbus et al, starting with 0.113 you will be able to do an "if" statement in a script. The new action option is called choose, and it can be used to implement an if - elif - else type statement (although due to the constraints of YAML it will look a little different. Don't ask! 😉 )
Okay I can't really figure this one out. I have this binary_sensor.last_alarm_triggered and I want to get it's last_updated and show it as x seconds/minutes/days ago and also be able to change seconds, minutes and days to other language
In the frontend you can show that in many cards, without writing a template
@arctic sorrel Isn't that only as secondary text?
Yes
I would like it to be the main
I have this shiny calendar variant of it but I'm not sure how I can convert it to use the binary sensor instead https://hastebin.com/tekefakiqo.cs
Okay I can't really figure this one out. I have this
binary_sensor.last_alarm_triggeredand I want to get it'slast_updatedand show it asx seconds/minutes/days ago
{{ relative_time(states. binary_sensor.last_alarm_triggered.last_updated) }}
Hi. Is it right, that time templates always gives me english values?
relative_time template filter does give only english
codebase of template language is not part of hass if i understand correctly
Yeah, all templates will give English results, even if your HA is set up to use another language. I haven't looked too closely but I think it's the Python installation or associated libraries that don't have i18n.
@plush harbor These behave differently. The first one works, the second one doesn't. I think it's because the last_changed isn't exposed as an attribute of the entity itself, it's just a 'hidden' property in HA.
{{ states.switch.bedroom_light_switch.last_changed }}
{{ state_attr("switch.bedroom_light_switch","last_changed") }}```
First gives an ISO datetime, second gives 'None'.
Also, just in case it matters to your automation... there are two similar properties, last_updated and last_changed. You'll find that last_updated is often more recent, since it'll be any updates, not just those that change the state.
And for bonus points - how to use these in an automation condition: https://community.home-assistant.io/t/how-do-i-use-state-last-changed-in-automation-condition/34465
thanks @ivory delta but when I tried the 1 line example, I get a TemplateSyntaxError: expected token 'end of print statement'
that's what led me down the state_attr route, specifically the complaint is got 'x00158dffffffffff'
Ahh... one sec
is there some sort of hex decoding issue?
yes, that solve it
ah, riiiiiiiight at the bottom of the documentation. my bad. Thanks @ivory delta
You're welcome
How do I set the on switch for a template when a device tracker reports not_home or home?
An 'on switch'? What are you trying to do?
template switch value template
I don't want to know your solution. What are you trying to do?
Trying to set the state of a switch if the device is connected
Why? What are you trying to do? You're still describing a solution.
Shutting down a computer basically
Why does that mean you need a switch?
Toggling the switch issues a cURL request that shuts down the computer
No. Turning the switch off might. Toggling goes both ways. What do you do when you turn it on?
🤦♂️
switch:
- platform: template
switches:
pc:
value_template: "{{ is_state('device_tracker.xxx', 'home') }}"
turn_on:
service: ... curl on
turn_off:
service: ... curl off
yep, I had set it to states instead lol
that'll get you a switch that turns on/off your pc.
@ivory delta take a chill pill. Not everyone is stupid.
Excuse me? Am I wrong to try to determine what someone's actually doing before jumping to conclusions?
It sounded like perhaps the wake_on_lan integration might have been a good fit. I was trying to check my understanding.
Yes, but you aren't being nice.
I appreciate all of y'all in the forums and dont want to cause any unnecessary discord.
well
wol is kinda useless to me cuz the laptop usually is awake or shut down (doesnt have a battery so...)
That makes sense. I didn't know it was a laptop.
Hi, preatty new to this but doing my best. Trying to make binary_sensor out of sensor. Found this code online, its a Nest Protect device (smoke detector). I use this :
binary_sensor: - platform: template sensors: badnest: frienly_name: "Nest Protect" value_template: >- {{ not is_state('sensor.hallway_nest_protect_co_status', "Ok") or not is_state('sensor.hallway_nest_protect_smoke_status', "Ok") or not is_state('sensor.hallway_nest_protect_battery_health', "Ok"). }}
i get error:
Invalid config for [binary_sensor.template]: [frienly_name] is an invalid option for [binary_sensor.template]. Check: binary_sensor.template->sensors->badnest->frienly_name. (See ?, line ?).
Anyone that can guide a noob? 🙂
frienly_name
should be friendly_name
when you see something like [frienly_name] is an invalid option for [binary_sensor.template] in an error message, it can mean you've misspelled whatever it mentions in the error
Oh just noticed that. I added friendy_name in hope that it will help but it was not the mail problem 😦
Invalid config for [binary_sensor.template]: invalid template (TemplateSyntaxError: expected name or number) for dictionary value @ data['sensors']['badnest']['value_template']. Got '{{ not is_state('sensor.hallway_nest_protect_co_status', "Ok") or not is_state('sensor.hallway_nest_protect_smoke_status', "Ok") or not is_state('sensor.hallway_nest_protect_battery_health', "Ok"). }}'. (See ?, line ?).
friendly*, its corrected now but a new error
probably doesn't like the period at the end of the value_template
What does that mean? 😫
or not is_state('sensor.hallway_nest_protect_battery_health', "Ok"). }}
remove the period at the end
Oh you are a god! Trying to figure this out for like 2 hours and I said "leets try discord". Thanks alot! that solved my problem!!! 😍
So i Try
So I try to use the code to get the sensor into my dashboard and even in homekit. But its status is triggered even if the status is "ok" on all 3 sensors, what is wrong? 😦
oh. check the actual state of those sensors at developer tools > states
states are case sensitive. i suspect the actual state is ok, not Ok
Already done, they are Ok
Also tryid this code but same thing: value_template: >-
{{ states('sensor.hallway_nest_protect_co_status') != 'Ok'
or states('sensor.hallway_nest_protect_smoke_status') != 'Ok'
or states('sensor.hallway_nest_protect_battery_health') != 'Ok' }}
what's the state of the binary sensor you created when all sensors are Ok?
In states it says: On
Ok, so thats why its "triggered" but why is the state "On" if all states on sensors are "Ok"?
are the entity IDs in the template correct?
What does the template render as in the templates dev tool?
Try them one at a time
It happens
Thanks again.
So here is a new "noob question":
I try to add a !include for binary_sensor and i point to a newly created file binary_sensor.yaml but i get an error.
Here is what i have in config: binary_sensor: !include binary_sensor.yaml
here is the error:
Invalid config for [binary_sensor]: required key not provided @ data['platform']. Got None. (See /config/configuration.yaml, line 13).
Where am I failing now ? 😦
yes, i tryed also to remove that one but i cant compile the file then.. but somewhere there is the problem?
what do you mean by "i cant compile the file then"?
First part of "binary_sensor.yaml"
binary_sensor: - platform: template sensors: # Contact Sensor alarm_ytterdorr:
right, remove binary_sensor: from the top
I mean, I cant save the file without getting error. My HA is in swedish 😒
Sec i will try it
Lol, works, I also removed - in front of - platform: template and thats why i could not save the file...
Like I said, noob. Sorry. Stil learning 🙂 thx alot, it Works now
@orchid onyx posted a code wall, it is moved here --> https://paste.ubuntu.com/p/mHNQpnXmwG/
- platform: template
sensors:
climate_hall:
friendly_name: 'Luftfuktighet'
...
Invalid config for [sensor.template]: expected a dictionary for dictionary value @ data['sensors']['climate_hall']. Got None expected a dictionary for dictionary value @ data['sensors']['device_class']. Got 'humidity' expected a dictionary for dictionary value @ data['sensors']['friendly_name']. Got 'Luftfuktighet' expected a dictionary for dictionary value @ data['sensors']['unit_of_measurement']. Got '%' expected a dictionary for dictionary value @ data['sensors']['value_template']. Got "{{ state_attr('climate.hall', 'current_humidity') }}". (See ?, line ?).
Ok got it now, it was the spaces infront of "friendly name"
Whats the correct name, not spaces but...?
Thx for help!
This condition template doesn't seem to be working, anybody have any ideas? It works in the dev tools template
value_template: "{{ trigger.from_state.state != 'unknown' }}"
maybe the .state is unneeded
i can never figure out when it is or isn't
The docs are the best way to remember 🙂
What do you mean by ‘not working’? trigger.from_state.state is ‘unknown’ in the action:?
There’s no way that’ll work in the template dev tool
I tested by doing a set, but it's not true test
What do you mean by ‘not working’?
trigger.from_state.stateis ‘unknown’ in theaction:?
it's a condition in the trigger
Thanks, that’s not trivial
And not everytime
Read the docs that I posted above
That’s not your problem
What is your evidence that it’s not working?
It's going from unknown to the version and alerting me
I don't think that logic is correct
you want something like "if the from state is not unknown or unavailable and the newest version isn't the one you're running, alert"
right?
I don't think you really want to "or" all those together
one of those first two will let it go right though because they're mutually exclusive
or I guess they're not, but I don't think it's what you want either



