#templates-archived
1 messages · Page 113 of 1
And I did a search of the config for other instances of history and recorder, and there's only one of each
Sure, one sec
sensors:
uptime_minutes:
friendly_name: Uptime (Minutes)
value_template: >
{{ ((as_timestamp(now()) - as_timestamp(states('input_datetime.last_start_helper'))) / 60) | round(0) }}```
Nothing special there
Thanks again for the help with the value template, btw. Works a treat 👌
whelp, just check for errors in your logs then
hi guys, need some help here
I have 5 input select sensor which are either off or a float
I need to catch those who aren't off and put them together as an array, i.e.
0,0,1,1,4,4
every input_select is either 'False' or '0,0' , '2,2', '4,4'
I'm trying to trigger 1hr before a calendar appointment, but just comparing unix timestamps seems to not actually be triggering. Currently I have {{ as_timestamp(states.calendar.my_calendar.attributes.start_time) - as_timestamp( now() ) == 3600 }}. Do I need to be a little less specific with the timestamps somehow? Like when the difference is =<3600 but > 3500 or so?
Hi all. I have a temperature sensor which always runs a little hot. If I want to drop it by say 7 degrees, what is the format for that if its current value template is:
value_template: '{{ value_json.temperature | round(1) }}' ?
@knotty dagger just add -7 to that
@fast vigil so, like this? value_template: '{{ value_json.temperature | round(1) -7 }}' ?
yeah, that should work
@fast vigil that did it. thanks, bud!
@bright veldt The template updates at the start of each minute, so unless the exact time down to every second is of the essence, I'd suggest {{ as_timestamp(states.calendar.my_calendar.attributes.start_time) - as_timestamp( now()) < 3600}} which then will become true when there is less than 3600 seconds left. So if you trigger on state to: 'true' you should be fine
Will it trigger repeatedly during that hour?
I used == so it would just trigger once. I’m fine with anytime around that time being the actual trigger
Oh, you’re saying to trigger only when it goes from false to true. Then it’ll only happen the once.
Can I use from: and to: with a template trigger, or just with a state trigger?
Reading the docs more closely, I see “Being a boolean expression the template must evaluate to false (or anything other than true) before the trigger will fire again. “ so i guess I can use <3600 instead of ==3600 and not worry about it!
Hi!
I have an automation that are triggered by different sensors. In the notification message I want to include the triggering sensor name.
I use this in my automation:
message: "{{ trigger.from_state.attributes.friendly_name }}"
Should I access the friendly name by using state_attr() ? If yes, how can I do it?
https://www.home-assistant.io/docs/configuration/templating/#states
Solved... message: "{{ state_attr(trigger.from_state.entity_id, 'friendly_name') }}"
Found a post in the forum explaining.. 🙂
The only reason edge case I can think of would be if a calendar is added with less than 60 min left to start_time.
It should still trigger those since the template would be true - but it will trigger with less than 60 minutes left.
I've been searching Google for quite a bit and my template-talent is not that great. I'm looking for an automation that triggers each time any of my Shelly devices has a firmware update. Are wildcards supported for this? trigger:
- platform: state
entity_id: binary_sensor.*_firmware_update
No you can not do that
Either you list all the binary sensor in the entity_id
Or you create instead an event trigger on the envent type state_changed
and check if the entity linked to the event matches your expression (binary_sensor.*_firmware_update)
{% if trigger.event.data.old_state.entity_id | regex_match('^binary_sensor\..*_firmware_update$') %} ...
Does anyone have an example of taking a list of entity ids and then returning true if at least one of the states is true.
Are they all the same type of entity?
yeah
You'd be better off just putting them in a group
doing an area blueprint selector for entity and noticed conditions started to fail and I just want to be sure at least one of them is true
eh.. blueprints are causing me much pain 😄
put them in a group and use the group state as your condition
Groups allow the user to combine multiple entities into one.
I can't use that
Why?
this is a blueprint. I can't control nor do I want to define groups for every single combo of lights the user picks
I'm getting a sorted list of entity ids and I just need to write a template to reduce to a single bool value if any of the states are on
- "{{ expand(motion_entities) | selectattr('state', 'eq', 'on') | list | count > 0 }}" does it but pretty sure it doesn't handle my case
Could someone using input_datetimes help me try to pinpoint an issue I am having?
If you type this in (with a valid input_datetime for you) are the times off by 18 minutes?
{{ states('input_datetime.heater_time_variable') }}
{{ state_attr('input_datetime.heater_time_variable', 'timestamp') | timestamp_local() }}
Is there a function I can use to always have a set number of decimals? I was hoping round(x, "ceil") would do the trick, but no.
Yes, like for example value_template: "{{ states('sensor.dehumidifier_power') | round(1) }}" will always show one decimal (unless you are on 0.116-0.118, then there were no decimals on "integers" like 26.0 would show up as 26, but on 2020.12.0 it is fixed).
Actually, it wont do what I need. I want to not strip the trailing zeroes, so to speak. So if I have a sensor with state 1.2, I want the ouput to be 1.200.
do you always want the same number of decimals?
👍
I have applied what I feel is a VERY diry workaround, not at least beacuse I mess with the actual value:
{{ ((state_attr('sensor.tidevann', 'high_tide_height') | float ) + (0.00000000000000100000000001)) | round(3, "ceil") }}
But, if there is a better way that is not messing with the value in this way, I'd be very interested!
'{{"{:.4f}".format(states('sensor.ping_router_roundtrip_max_tmpl') | float) }}' will always give you 4 decimals.
the 4 in .4f decides the number of decimals. I haven't actually verified it, but it should round correctly as well
so 1.2 will become 1.2000 in the example above
Let me check! 🙂
It works perfectly!!
Thank you so much!
No.... It works in the template editor, but not in Lovelace....
This is the weirdest thing....
If that template is the only thing being rendered it doesn't work! But if anything is added it works as expected....?
When you use a single template, you'll see the true value. When you use multiple templates, the dev tools makes a multi-line string with all the results.
Single = truth
Too slow, thomas 😉
Was double checking a workaround that doesn't work... around. Don't mind me.
Ok, got another workaround that does work.
The problem is that the template engine will always interpret a number as a number nowadays, even a string containing a number.
But I want the extended truth! 😛
So you do all of that work to make 1.2 display as "1.200", but then python says, "Hey! I know what that means! That's 1.2"
Haha!
but it you instead make is say "1.200\x00" python will say "Hey! I know what that means! It means '1.200' and is a string, obvisusly!".
"\x00" will add a non-printing empty byte to the string.
This will stop you from making string comparisons, though, unless you accommodate for the null byte too.
Try '{{"{:.3f}\x00".format(states('sensor.ping_router_roundtrip_max_tmpl') | float) }}'
Not a problem! I simpy want 3 decimals! 🙂
You're not the first to run into this problem, but I realized the solution only right now. So thank you!
Hehe... That is a very generous way to look at it! 😉
Finally the numbers align!
Really enjoyed your talk yesterday btw! 👍
Glad to hear it! I look forward to seeing it myself, actually.
So first time messing around with templates.
I am trying to do a template_sensor which uses a value of one sensor if its bigger than 0 and a other one if below
Thats what i came up with but it doesn't work:
{% set consumption = states('sensor.e3dc_home') %}
{% if consumption > 0 %}{{ consumption }}
{% else %}{{ states('sensor.e3dc_grid') }}
figured it out... {% endif %} was missing
Also, need to cast consumption to a float or an int
I have a lightbulb that I flashed Tasmota (8.5.0) to and recently upgraded Tasmota (9.1.0) and now the light's rgb_color attribute always shows 255,255,255. I looked at the MQTT output and Tasmota is sending the RGB in hex (for example Green would be: 00FF00). Is there an easy way to convert/format the value template so the rgb_color attribute reads correctly? I use the rgb_color attribute in a node-red switch to do different actions. Thanks.
@ivory delta thanks, I've already read that link, but I need to go the other way. Hex to Decimal
in that same article it suggests using '{{ value | int(value,16) }}' to convert Hex to Decimal, I'm just wondering if there's a way to do this with a format, rather than split the Hex string into 3 pieces, and run an int(value,16) on each, and then concat them back into an array.
Hi @raw dust did you ever found a way to do this? I'm trying to find the device name given a device_id...
no, unfortunately not
@crimson quarry there's no quick easy way to do this in jinja. Here's your best option...
{% set value = '00FF00' %}
{% set rgb = namespace(value=[]) %}
{% for i in range(0, value | length, 2) %}
{% set current = value[i:i+2] %}
{% set rgb.value = rgb.value + [ current | int(current, 16) ] %}
{% endfor %}
{{ rgb.value }}
and the other way
{% set value = (0, 255, 0) %}
{% set hex = namespace(value='') %}
{% for i in value %}
{% set hex.value = hex.value + '%02X'%i %}
{% endfor %}
{{ hex.value }}
hi can anyone please tell me why this wont work ? it works in developer tools when i tested it
- platform: mqtt
state_topic: "zigbee2mqtt/switch1"
name: SW1
value_template: >-
{% if as_timestamp(states.sensor.sw1.last_updated) + 5 < as_timestamp(now()) %}
{{value_json.action}}
{% else %}
blank
{% endif %}
think you replied to the wrong person 😉
Oh my, I am sorry petro... 😦
I am not a master at templates, but did you try {{ value_json.action }} instead of {{value_json.action}}?
what section are you putting that in? Also, what are the intentions of that? It seems you only want to store the information if it's older than 5 seconds?
yes it a zigbee button and i wont to change its state after 5 seconds of pressesing the button .
its in the MQTT sensors section just trying to condition the value..
So when you press the button, you want it to keep the pressed state for 5 seconds then return to 'empty' or something?
the conditoin is not working properlu
yes 🙂
sensor 🙂
Ok, just use this template but set expire_after
value_template: "{{ value_json.action }}"
expire_after: 5
after 5 seconds it will return to a 'unavailable' state
np
@mighty ledge you are the man ❤️ thank you very very very much hehe
but i still don't get why the formula wasn't working altho nevermind u dont have to explain thanks again 🙂
It depends on the scope of templates
I'm not sure what the MQTT value_template scope is. It might not have access to the state machine
But you're also referencing itself
so, thats a no no
Could someone explain to me, in templates, when to use == vs ===?
@mighty ledge thanks you well noted 🙂
In jinja templates the difference is a valid template or an invalid template
=== is only used in JS
ok, thanks
sure
== makes both sides the same type. === does not alter the types
gotcha, thanks
Nice! I had it wrong then :D
I thought == matched value, and === was type + value 😄
Isn't that the same thing?
yeah it is
It == is, but not === is
== changes them both to the same type essentially, where === needs them both to be the same type to pass
ah, okey, we agree then 😄
Yep
I'm sure there's better ways to describe it. It's just what I rememeber
I'm no expert at JS
Is there a template to get the max value from another sensor in the last week or do I have to use the statistics sensor?
hi there, I'd like to use an template sensor to fill the value of input_number but I'm unsure what's the proper way to do such "binding". any ideas?
With an automation
hmm 😦
oh. actually I may not even need to do template extraction in that case
oh well, it's not the prettiest thing I have ever encountered, but state change -> input_number.set_value works good enough for the christmas lights 🙂 thanks @hollow bramble
Hi there. I hope that someone can help me understand templates a bit...which is what I think I need.
I have a garage door which reports on the status "open" or "closed" - I have it in another group with a couple of door locks which obviously report "locked" or "unlocked".... I'd like to have the garage door as part of this group and then report the group as "off" whenever the doors are locked and the garage door is closed - Is a template the right solution to what I'm trying to achieve, and if so, heeelp 🙂
With a template binary sensor you could do something like {{ is_state('cover.garage', 'open') or is_state('group.locks', 'unlocked') }}
It will only have a state of off if everything is locked/closed
Thank you for that response Villhellm - Not entirely sure how I can incorporate that into my configuration yaml tho...If I mention the names of the sensors, any chance you can help me piece it together?
- platform: template
sensors:
custom_garage:
friendly_name: "Custom Garage"
value_template: "{{ is_state('cover.garage', 'open') or is_state('group.locks', 'unlocked') }}"
@wet latch
that goes under binary_sensor:
assuming entity ids and group names are correct
Uh, cool @pallid lake I'll try to create that and make the modifications needed. Ty ty
np
Hello everyone, I have a problem with templating a binary sensor. The original sensor has value between -100 and 100. I would like to set the binary sensor to 'on' if the original sensor value is between 30 and 60 and to off if the original sensor is between -30 and -60. And the value remain the same (on or off) for all others value.
I've tried this : http://pastebin.com/NdV7tkwF
But for other values not captured by the 'if', the sensor does not stay at the same value but goes back to 'off'
You have to use statistics
There is a min max sensor in my memories but I don't know if it still exist
Yeah but he can't use a template sensor, it has to be an integration that traverses the state history
which min max sensor do ifr
iirc*
{% set weight_change = state_attr('sensor.bed_stats', 'change') | int %}
{% if 30 < weight_change < 70 %}
on
{% elif -30 > weight_change > -70 %}
off
{% else %}
{{ states('sensor.bed_occupancy') }}
{% endif %}
@mighty ledge Thanks. I am having issues with my statistics sensors showing unknown state. I ended up using a SQL sensor but its a bit more convoluted than I would like
So simple, so elegant, will try this... Thanks for your help
@pallid lake - May I disturb you once more? I added the sensor and it seems to work...it does however only report the status of "True" if every group member is unlocked (or Open I guess) - I'm trying to create a group that reports something I can pick up for an automation that reminds me if I leave the house or go to bed at night with a door unlocked
"{{ expand('group.locks') | selectattr('state', 'eq', 'unlocked') | map(attribute='name') | list | join(', ') }} are unlocked!"
Don't know if this is the right section so forgive me if im wrong
I have made a mqtt binarie sensor for motion detection but i have multiple payloads that can be sent
These are
- Car
- Face 1 my wife
- Face 2 my self
- Face 3 kid
- Face 4 kid
- Dog
What would be the best approach to make it work?
Using a template condition, is it possible to extract the event_type of the trigger event. Using {{ trigger.event }} gives something like <Event ios.action_fired[R]: actiionID=someID, ...> I just want to check if the event type was ios.action_fired or not.
Obviously there are multiple triggers and I just want to take an extra step in the action if it matches this case
Dirty solution I have is {{ "ios.action_fired" in (trigger.event|string) }} but I feel there should be a better way
@mighty ledge thank you, I'll try - Fingers crossed 😄
Did you try {{ trigger.event.event_type == "ios.action_fired" }} ?
I'm trying to send an image with my notify.notify but I get the message sent to my android phone which has the HA Companion app installed. I'm only receiving the message notification, but there is no image. Am I doing something wrong?
message: This is a test message with a picture title: Test Title data: photo: url: "https://raw.githubusercontent.com/home-assistant/home-assistant.io/current/source/images/default-social.png"
That is not a #templates-archived related issue. I recommend #android-archived
The symptom happens on all devices.
This is what it looks like on the phone for example: https://i.imgur.com/czu4jtZ.png
This is still not a #templates-archived topics 🙂
Where would be ideal to discuss the usage of notify.notify ?
I'd start with #integrations-archived
I noticed that last_changed only changes with state itself (eg on>off), but not with attributes (brightness,hue), well at least for bulbs.
Is this concise behavior I can depend on automations?
Because it contradicts a bit with docs
https://www.home-assistant.io/integrations/history/#implementation-details
why do you say in contradicts with docs ?
last_changed is updated when the state changes, last_updated is updated when the state or attributes change
That is what you noticed and what is in the doc. Or am I missing something?
A
state_changedevent can happen when just attributes change
would mean I cannot depend on it on major state changes because it could change with just 1 attribute change.
no, this just says that when an attribute or a state changes, a state_event happend, it is not in contradiction with what we sayd
if you use event trigger, it means you should pay attention rather it is a state change or just an attribute change
ok, I get it, It references event not the last_changed itself.
so last_changed is guaranteed to fire only on state change?
yes
ok, this is what I wanted to know. Thank You.
Welcome
hey all, I am trying to send a telegram notification. Notifications is configured correctly as I can send simple text
But I would like to send the automation trigger name as part of the message
this is my current automation
`alias: Network monitor
description: ''
trigger:
- platform: state
entity_id: binary_sensor.garage_rb_ping
to: 'off'
condition: []
action: - service: notify.telegram_henk
data:
message: ' {{ trigger.to_state.name }} '
mode: single`
whenever I use the trigger I get an error
Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: UndefinedError: 'trigger' is undefined
I use for: in my automation condition. But, when i reset my server, the device goes to 'unavailable' for a couple of mins which causes the counter to starts again. Can i still use for but ignore unavilable time? - condition: state entity_id: vacuum.robovac state: 'off' for: hours: 71
There is no such things as trigger.to_state.name
There is, that's not the issue
oh yes, indeed, sorry about that
The issue is that it was triggered manually, when you do that, it only run the action part, which does not have the trigger context
ah, ok
that makes alot of sense, it did cross my mine
let me do a propper trigger change test
This automation triggered when the state of weather.dark_sky changed to "snowy" but is not turning on the switch. Can anyone see an issue with the code? It was suggested that I may want in not == https://paste.ubuntu.com/p/cNx7JjpBdS/
thanks @rugged laurel I was just testing it wrong.
hi all , I have made this temporary automation (https://hastebin.com/isiyugubis.kotlin) as a sanity check with some templating inside the inline_keyboard part which actually petro helped me and it works - if I trigger the automation manually the message comes and the buttons work with my callbacks (which I have on another file). The very same code when I put it inside an alert like so (https://hastebin.com/owujeyurez.java) returns an error in the logs , seems like from Telegram API that the Button data is bad. The only change between the codes is that in the working instance its A) an automation and B) I am sending to my personal chat with my bot , whereas in the non-working instance its A) an alert and B) I am sending to a group chat where the bot participates.
In the non working instance if in inline keyboard I hardcode the outcome of the template like so:
inline_keybaord: [ 'option1:/callbackbutton1' , 'option2:/callbackbutton2', ...etc ]
it works.
Could someone offer me some insight as to what might be giving this issue?
@spiral imp yes, you want in. == is for equality, and your state is never going to be equal to a list. in is true if the state value is in the list.
Thanks! Is there somewhere that is documented so I can read up on it?
Well, the logic inside the double brackets is essentially Python syntax. But if you really want to know it all, look for the links to Jinga2 templating in the URL shown in this channel's header.
Thanks. I feel like I have been on that page 100 times as I am creating templates. The use of "in" was not one I had ever noticed. Thanks for the help
Hi! I have 2 sensors at garage door. If I close the door I receive ON on the first sensor if I open the door I receive status ON on the second sensor. From these 2 sensors I would like to create a virtual "sensor" which will combine the status of these 2 sensors: so when
first is ON => closed,
first changes from ON to OFF => opening,
second is ON => open
second is OFF => opening
what is the best practice to achieve this?
how to create that "virtual" sensor
?
Hi everyone
Does anyone know how to get the current user's name in a template?
sorry, I'm new to HA
🙂
is the template some kind of "virtual" thing? like virtual sensor without physical sensor?
I have a bulb where I can set the warmth, and I use a button for that - I just decrease or increase the current mired value. color_temp: '{{ state_attr(''light.desk'', ''color_temp'') | int - 50}}'
Now the issue is that the button can take the bulb past its limits.
It doesn't explode, but then the value is stuck in unattainable limbo, and I have to click my way back to the attainable range with the button on the other side.
Is there a way to make the template return the minimum or maximum of two numbers? That way I'd cap it to the bulb limits.
Ah, I think I can get there
color_temp: '{{ [state_attr(''light.desk'', ''color_temp'') | int - 50 , state_attr(''light.desk'', ''min_mireds'') | int]| max}}'
Thanks 🙂
So what are templates?
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)
The one command that doesn't work the way you'd want 😄
yeah, that one is a pain because of how the docs scraper tool works
I find this better: https://www.home-assistant.io/docs/configuration/templating/
https://www.home-assistant.io/docs/automation/templating/
https://www.home-assistant.io/docs/configuration/templating/
haha
Oooh, I didn't know you could do all these things. Very useful.
alright jinja gurus need some help...these date/time templates are always painful for me lol.....so one of hte breaking changes in 2020.12 was cert expiry no longer showing how many days left...we get a timestamp sensor....so how would i go about creating a template sensor that gives me back that countdown?
well that was simple enough
{{ ((as_timestamp(states('sensor.cert_expiry_timestamp_domain')) - as_timestamp(now())) /60 /60 /24) | int }}
You could make it a tiny bit shorter as
{{ (as_timestamp(states('sensor.cert_expiry_timestamp_domain')) - as_timestamp(now())) /60 /60 //24}}
I think this is the correct place to ask, I'm seeing a lot of errors in my log that are similar to this
[31m2020-12-17 08:52:00 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: E664DEOff, template: {{value_json.RfReceived.Data}})[0m
They seem to be appearing for most (there are lots, so i'm not sure if it is all) of my motion sensors, they are setup in binary_sensors.yaml like:
- platform: mqtt
state_topic: "tele/RF_Bridge/RESULT"
name: 'motion_livingroom'
value_template: '{{value_json.RfReceived.Data}}'
payload_on: 'E664DE'
payload_off: 'E664DEOff'
device_class: Motion
qos: 1
Once the motion sensors are activated, i have a flow in node red that waits 30 seconds before adding the offpayload to mqtt.
If I understand correctly the error message, it says the payload (value) is E664DEOff (so, not a JSON), but you consider it as a json using value_json.
If that is correct, just remove value_template: and you are good
Thanks, just going to try that now.
by removing that none of my motion sensors are activating. the errors were also gone though.
Is there a way to give a variabel a list of entries? So that i can check with a single condition if for example one of the artists is playing that is present on the list and mute the radio for example?
Something like this for example
- entry 1
- entry 2```
to fill a condition like this
- "{{ is_state_attr('media_player.android_tv', 'artist', '{{variable}}') }}"```
@young jacinth posted a code wall, it is moved here --> https://paste.ubuntu.com/p/7C2Rt5mFPJ/
ups..
why is this giving me an error while the template works fine in the template editor?
im no pro but i have a template that works and looks like this: https://paste.ubuntu.com/p/n3qw6hzDgw/ maybe its missing the "-" ??
mh no that does not work..
same error
oh it was a slide in error (its that how its called?) in the template. its working now. damn yaml 🤣
2 spaces you mean?
value_template: >
{% if is_state_attr('remote.harmony_hub', 'current_activity', 'PowerOff') %}```
instead of:
value_template: >
{% if is_state_attr('remote.harmony_hub', 'current_activity', 'PowerOff') %}```
yes
yeah spaces can be a pain
how to get average value of sensor with respect to a time range ? 🙏
Take a look at https://www.home-assistant.io/integrations/statistics
I have made this temporary automation (https://hastebin.com/isiyugubis.kotlin) as a sanity check with some templating inside the inline_keyboard part which actually petro helped me and it works - if I trigger the automation manually the message comes and the buttons work with my callbacks (which I have on another file). The very same code when I put it inside an alert like so (https://hastebin.com/owujeyurez.java) returns an error in the logs , seems like from Telegram API that the Button data is bad. The only change between the codes is that in the working instance its A) an automation and B) I am sending to my personal chat with my bot , whereas in the non-working instance its A) an alert and B) I am sending to a group chat where the bot participates.
In the non working instance if in inline keyboard I hardcode the outcome of the template like so:
inline_keybaord: [ 'option1:/callbackbutton1' , 'option2:/callbackbutton2', ...etc ]
it works.
Some guidance on what might be going wrong?
This template It is {{ states('sensor.dark_sky_current_text') }} today. returns "It is Cloudy today". Can I change it to "It is cloudy today" without changing the sensor?
Yes but since I am on phone I could only describe the rough process to you until later on that i will be on pc
Would you care for that?
sure, that is fine
Essentially what you want is to get that value and pass it through template filters. So make it a string type first if it isn't already. And then use another filter like many languages have usually it's called "split" or "slice" to get the first letter of the string. Then yet another to turn it to lower case. Again should be called toLowerCase or lowerCase or something similar.
All those should be able to be found in the templates documentation of home assistant.
thanks, will do some digging
Actually, it was simple. This worked... It is {{ states('sensor.dark_sky_current_text') | lower }} today.
Nice. Well played!
how can i mius the time now ? like this format 2020-12-17 23:48:31.925237+08:00 but i wanne do now() - 60 minutes
It possible to include two states in an if_state if I want to return the same value for both? I tried this but it did not work:
{% if is_state('sensor.part_of_day', ['Morning','Afternoon']) %} today {% else %} tonight {% endif %} It does work if I use just 'Morning'
@spiral imp I saw something yesterday about you using in. You could do the same now. There may very well be slicker solutions, but this should work:
{% if states('sensor.part_of_day') in ['Morning', 'Afternoon'] %} today {% else %} tonight {% endif %}
There may be an easier way, but this gets you there:
{{ (as_timestamp(now()) - 3600) | timestamp_custom('%Y-%m-%d %H:%M:%S.%f%z') }}
Thanks figured it out ❤️
btw is there a way to set variables inside config yaml as a global ? to use all around ?
no
❤️ YES!
but you can't use them in templates
kinda
Expose them in a hidden input_text 😄
variables:
yo: !secret myvar
action:
- service: something.bla
data:
message: " Test {{yo}}"
untested, but I think it should work
Beautiful!
I have a sensor which exposes nothing as entities and just has a big list of state.attributes. Am I right in thinking templates are the only way to pull this data out?
Trying to use a template in a entity_id for media_player but keep getting error, it not possible?
sequence:
- service: media_player.media_pause
entity_id: '{{ media_player1 }}'
media_player1 is a variable
- variables:
media_player1: "media_player.master_bathroom"
@brisk temple if you use a template for the entity_id, you have to put it under data:
sequence:
- service: media_player.media_pause
data:
entity_id: '{{ media_player1 }}'
I tried data but got the same I thought, I'll try again
all seems good with that, thanks @deft timber
Hi, someone can help me with the scrape sensor, i was trying to get the stock value at this adresse
https://money.tmx.com/en/quote/BU
- platform: scrape
name: Bu Stock Price
resource: https://money.tmx.com/en/quote/BU
select: ".hwRiQ"
scan_interval: 60
not working a get a unknown state
wget -q -O- https://money.tmx.com/en/quote/BU | grep hwRiQ returns me nothing. Are you about the hwRiQ ?
Not really, I'm not really good in html css I try to find the correct thing maybe such sc-jOvPaO.hwRiQ
it seems this value is provided by a 'subpage' (called by js or so), not sure (and apparently it is not the cas) that HA is going down, it just get the content of the URL, it doesn't interpret the page to call sub-documents/xhr
Oh ok maybe i can write a script with some regex to get the value
Maybe i can write a php page with some regex an run it every minute on my website and get the content of my page with HA
yes, that you can do
or just a shell_command
using what i pasted above
the curl and then use jq to get the value in the json
Ok i ll try with sell command
Command 'jq' not found, but can be installed with: sudo apt install jq
nicecube@DESKTOP-9H6FOG1:~$ sudo apt install jq
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package jq
If i can't run it in ubunutu i don't think my docker ll run it
Yes ty very mutch its working, you are really good 🙂
🙂 you are welcome
Hi guys, I'm trying to grab a specific set of numbers that are a part of a calendar event
I want to grab the last 4 digits of these calendar event to set up a lock code
https://www.home-assistant.io/docs/automation/templating/ Im trying to wrap my head around the documention here but I think i need a little nudging
to be honest I don't even know where to start. this is my first experience with templates
is the data in home assistant?
I should be able to get the data by using {{ states.calendar.airbnbcal.attributes.description
its in the description portion, but I dont know how to filter out the other text and stuff
is it always at the end?
it should be, unless airbnb changes their format
which is a gamble im willing to take until i get more comfortable with templates
k
{{ state_attr('calendar.airbnbcal', 'description').split("Digits): ")[1] }}
give that a go @quaint seal
selects the second item in the list
if you go to your template editor and put in {{ state_attr('calendar.airbnbcal', 'description').split("Digits): ") }}
you'll see there are 2 items
[0] for the first, [1] for the second, etc
ya, for the life of me I can't find documentation about it, I figured it was a jinja filter, but doesn't seem to be
did i get that right
yes
you are a legend
a legend wouldn't have taken 15 minutes to figure it out
that is infinitely faster than me
hi, any idea how to create sensor template with value from mqtt
in this format
home/OpenMQTTGateway_SRFB/PilighttoMQTT {"message":{"unit":692,"state":"opened"},"protocol":"iwds07","length":"","value":"692","repeats":2,"status":2}
with mqtt auto discovery openmqttgateway is creating gateway pilighttomqtt with every message which is not very usable 🙂
thank you 🙂
Does anyone know why a template for a time stamp would show properly in the dev tools template area but when I use the template to be part of a file name, it turns it into (seemingly) random characters? This is the template I’m using:
{{ as_timestamp(strptime(state_attr('automation.notify_camera_person_event', 'last_triggered'), '%M-%D-%Y %H:%M:%S')) | timestamp_custom('%m-%d-%y %I:%M:%S%p') }}
probably because of the : character
That worked! Thank you! Didn’t even think of that
Greetings. I'm just getting started with HA and would like to find a way to change the entity being displayed from On/Off to Open/Closed. Can this be done on the card itself via the visual editor, or would I need to make some entries into the .yaml files?
My card on the dashboard is just referencing the entity binary_sensor.shelly_1_xxxxxxxxxx_input_0
any idea how to match the unit inside the message ? because i have different unit ids and need to create sensor for every id, with the following example i create 1 sensor with different unit/state attributes
change device class of binary sensor to door ?
device_class: Door
how to use template on mqtt.publish topic: ?
i'm successfully using payload_template, but cannot template the topic ?
@eternal saddle Yes. And it's well documented when you know what to look for. Have a look here: https://www.home-assistant.io/docs/configuration/customizing-devices and here https://www.home-assistant.io/integrations/binary_sensor/ as a start
Do you have to import int in a template for it to work? I keep getting undefined when calling it
Or testing something that can't be tested in
> Templates 🤷♂️
"{{int(trigger.event.data.args.activated_face)}}"
Yeah... wrong for two reasons.
service: input_select.select_option
entity_id: input_select.alisa_cube
data: "{{int(trigger.event.data.args.activated_face)}}"
Casting to an int is done like so... {{ some_value | int }}
And you can't test a trigger in the dev tools (like I told you in #automations-archived)
I know that testing part @ivory delta.... i am not getting undefiend on the trigger. I am able to test it but triggering a fake event
You will as soon as you fix the cast.
https://jinja.palletsprojects.com/en/master/templates/#int which i got from the ha temp docs made it seem like it was a method
that's still a filter
@mighty ledge ok ty
applied like this
{{ value | int('', base) }}
but if the base is 10, then it's just {{ value | int }}
@ivory delta i understood what you said about triggers in templates and that is not why I asked ab out them here
ahhhhh that is what I was missing @mighty ledge
ty
You can stop tagging me now...
We're all reasonably intelligent. We can tell from the context of the conversation which reply is intended for whom.
its working now. Thanks petro.
is there any way to template mqtt.publish topic , not only payload
i'm finding some old forum topics, but currently dont work
only way you can is through mqtt.publish
yeah but service mqtt.publish seems does not support template on topic?
it supports templates on all items inside the data field
you can't use templates in the service checker in the UI
yeah i know that, trying in automation action, but only work with static topic
topic: '/home/sensor' is ok
topic: '/home/sensor' + {{ sensor.id }} should work?
thanks will try that
yes it is OK, I see it as payload
that doesn't make sense
thanks will try now
yeah my mistake, sensor was for example
topic: "home/sensor/{{ trigger.payload_json.protocol}}/{{ trigger.payload_json.message.id }}"
payload_template: '{{ trigger.payload_json.message.temperature }}'
this is ok, working now
thanks @mighty ledge
i see, thanks
Hey folks - I have a contact sensor on my garage door to capture the state of the door. Because of where/how I mounted the sensor, when the door is closed, the contact sensor separates and the state of binary_sensor.garage_door reads as "open". So I wrote this template sensor to reverse that, so the state actually matches the door position. But having trouble with the template - which always evaluates to "open"
sensor:
- platform: template
sensors:
garage_inverted:
friendly_name: "Garage (Inv)"
value_template: >-
{% if states('sensor.garage_door_sensor') == 'on' %}
Closed
{% else %}
Open
{% endif %}```
You want a binary sensor, not a sensor.
So your template will just be the inverse of the original: {{ states('sensor.garage_door_sensor') == 'off' }}
That'll evaluate to True if the sensor is off, False if it's on. Then just set the device class as 'door' to get Lovelace to say Open/Closed.
@meager orchid ☝️
@ivory delta perfect, got it working - thanks
I have a sensor template that works. It returns text. What card type would I use to show the text?
This is the sensor template I'm playing with https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/wiki/Example-Automations-and-Templates#post-0115
@dull ledge would the markdown card work for you? https://www.home-assistant.io/lovelace/markdown/
Yeah. That worked if I moved the template code into the card.
I could be wrong, but if you already have that template set up as a sensor in your config, I think all you need in the markdown card is {{ states('sensor.nameofyoursensor' }}
are templates able to access mqtt directly?
what u mean? automation can be triggered by mqtt message
and you can use template on payload
Their question was 3 hours ago. You may need to tag them to get their attention.
sorry, didnt notice that, thanks @ivory delta
@restive flume ^^
@restive flume only through events or MQTT <domains> like MQTT sensor, MQTT light, etc
Hi All !, i have some sensors counting the number of times an event happened during the day , the sensors stopped working and cant figure why?, it seams that sensors related to TIME are having issues in my config : for example https://hastebin.com/oxusebavam.yaml , any hints appreciated .
Hi all lovely helpful people! I have almost 1000 lines in my sensor.yaml file and would like to split the file up in several files based on content. I have read https://www.home-assistant.io/docs/configuration/splitting_configuration/ but having a hard time figuring out how to..
i thought that a '''sensor: !include_dir_merge_named sensors/''' would include all files in the directory sensors?
when am I ever going to learn that three backticks markup..
solved it! sensor: !include_dir_merge_list sensors will include all files in the subfolder "sensors"
have a great day everyone 🙂
@drifting plaza looks fine, is that entity name right? the a at the end of alarm looks out of place
I need help writing a condition (or maybe changing the trigger?) for this https://paste.ubuntu.com/p/5zBqVKp4BN/
I have a feeling my condition loop will fail miserably
it will never be true true
With template types is it possible to force a numeric value to a string piping to string still returns a number. I.e. the type of: {{ state_attr('device_tracker.toms_iphone', 'latitude') | string }} is number I've tried even adding on an empty string on the end but it looks like the typing is done post Jinja
@grave arrow the typing is done after resolution of the template
Why do you want this?
iOS notifications can provide a map pointer which you pass lat/long to. This requires a string value at the moment and fails if a float is passed. We can do the typing on the push server to fix but I feel like there are other cases where a specified type should be respected.
The difficulty is that HA casts to a sensible type automatically. This has changed slightly with the new ability to return native types (dicts/lists/etc) from a template but it's now each integration's responsibility to handle the incoming types.
That said... someone came up with a workaround that might help your specific use case. Gimme a minute to dig it out.
This should do the trick, @grave arrow : #templates-archived message
Ooo that’s smart. Going to fix server side though rather than put that in docs it’s not exactly user friendly I think.
Hello, can somebody help me with a template for an automation? I need to publish the current temperature from one of my aqara sensors every x seconds to a certain mqtt topic. I have until now something but it does not work:
- alias: 'send temp'
trigger:- platform: time
minutes: /3
seconds: '0'
action:
service: mqtt.publish
data_template:
payload_template: '{{ states.sensor.0x00158d000465809a_temperature.state }}'
topic: 'opentherm-thermostat/current-temperature/set'
- platform: time
I don't see a data_template attribute for mqtt.publish; I think you want ```
action:
service: mqtt.publish
data:
payload_template: '{{ states.sensor.0x00158d000465809a_temperature.state }}'
topic: 'opentherm-thermostat/current-temperature/set'
Ill try this. Thanks.
Not working yet.
I do not know exactly how to test the automation in dev tools - states
I am not sure the payload template is correct
Plug that template into dev tools->templates and you can see what it's actually resolving to
I am doing this,
and the problem is with the syntax
I really do not know what should be there
try {{ states('sensor.0x00158d000465809a_temperature') }} instead maybe
that looks good to go, now i get an error in yaml file:
can not read a block mapping entry; a multiline key may not be an implicit key at line 254, column 12:
topic: opentherm-thermostat/current-t ...
for topic word
That sounds like maybe wrong indentation, or not having the payload as one line and the topic as one line. I don't know how multi-line strings work in yaml
I posted on the forums and ill wait to see what happens.
Good deal, sorry I couldn't help you further; I'm still learning too
When using a device as a trigger, what template would I use to get an attribute state of the triggering device? I see {{ trigger.event.data.event }} for a different type of trigger that was not platform: device
Hey, I'm not sure if this is the right place to ask, but someone mentioned somewhere about making sensor groups, so if I have two sensors, the group state would be on as long as any sensor would be on, and it would only be off when all sensors are off
How would I do something like this?
Do I just set up a template and have its state in a helper?
Thank you so much
no problem
How would I create a template sensor that tracked my kWh consumed from solar generation in a day? I have solar generated, house draw already - problem being that I only want to track solar generated - house draw only while solar is actually being generated.
@eternal saddle posted a code wall, it is moved here --> https://paste.ubuntu.com/p/snH5SbCfJh/
this seems like it should be really simple, but I'm completely stuck. How do I get the sunset/sunset time as a relative time? the output of the sun.sun next_setting attribute doesn't work with the relative_time function
isn't the "sun.sun next_setting" already a relative time?
No, it's an absolute time: next_setting: '2020-12-21T15:40:58+00:00'
@tardy patio your object_id starts with a number. If you want to use the states object instead of the method then you need to access the item as if it were a dictionary key. {{ states.sensor['0x00158d000465809a_temperature'].state }}
Thank you @mighty ledge I managed to resolve the issue with: data: {"payload": "{{ states('sensor.0x00158d000465809a_temperature') }}", "topic": "opentherm-thermostat/current-temperature/set", "qos": 0, "retain": 0} with the help of user shcherban on the community forumns
Now I am trying to start a very big project for me, with multi zone heating control.
might be easier to read if you don't treat it as a dictionary.
data:
payload: "{{ states('sensor.0x00158d000465809a_temperature') }}"
topic: opentherm-thermostat/current-temperature/set
qos: 0
retain: 0
Yep, I know, just copy pasted it as I received it 🙂
If you want and have some time, anytime, please, take a look in my mess of a project here: https://community.home-assistant.io/t/entire-project-for-multi-area-zone-heating-cooling-open-window-control/258182
I think I need only some hints to build it up to work. Ill add more details lated.
later
Seeing that you understand flowcharts better than code, I suggest you use node red as an automation engine over the built in automations.
that's the thing, you're either wired for it or you're not
work with what you got. I'm not wired for flowcharts
so I use code
and I think I just need very little info, like, I do not know if an automation can have multiple actions added, I do not know if the action from automation can pickup a value from an mqtt topic and publish it forward
Yes they can
🙂
- service: blah.1
data: ...
- service: blah.2
data: ...
the dashes indicate each 'action' in the action section
yes, that part ii understand. good.
see how your trigger has that?
yes
each section can have multiple
well, each major section: trigger, condition, and action
You should read up on how to format conditions
and your trigger will not give you the ability to see what's on your MQTT topics
what's not enough about the conditions page?
are you reading or skimming?
so what's the problem?
I am not sure if I can make something like:
@thorny snow - try something like this: {{ states.sensor | map(attribute="entity_id") | list }}. You can change the domain after states. to report on other types.
having 2 rooms, each with 2 temperatures, let's say minimum and maximum (each published on its own mqtt topic)
That template will output a list of all the entity ID's of all sensors.
Thanks, will do!
if you have 2 mqtt topics with 2 different sensors, then you should make 2 mqtt sensors
create triggers based on those sensors changing.
can an automation compare these and publish the pair of minimum to a new mqtt topic1 and maximum to new topic2 from the room with the biggest difference between maximum-minimum?
I need to have the vaclue updated every 20-30 seconds,
why do you need this?
so I thought I should have the trigger as time_pattern
long message: “Automation algorithm”: This should be the multi area/zone calculator. This automation should receive set temp dummy 2 and current temp dummy from each room, make pairs of them, and calculate which room has the greatest difference of temperature (set temp-current temp) and send this data to the ot shield.
By doing this, the boiler will always work for the room that needs heating the most, and the automation for the TRVs will prevent other rooms from getting overheated.
yes that's fine, but you'll have a periodic result instead of a live result
I need to send this temperature to an opentherm controller, so the boiler knows what to do.
Any idea how to copy that list, so I can work on it in an editor? In the UI I can only select what's on one page. As soon as I scroll it deselects everything. And the list is quite long ...
Ok, so first order of business is that yous hould get your sensor values into home assistant
I have the sensors in home assistant.
this would be done by making MQTT sensors that read from the topics
Then you'll make an auotmation that has a time period that updates every 30 seconds.
You'll have 2 actions. 1 that publishes the min
1 that publishes the max
you're going to be using a template for each result that's getting pubished
this is your template for min:
{{ expand('sensor.abc', 'sensor.xyz') | map(attribute='state') | map('int') | list | min }}
this is your template for max:
{{ expand('sensor.abc', 'sensor.xyz') | map(attribute='state') | map('int') | list | max }}
if you want you can use variables so you only have 1 input list
I can scroll just fine in Chrome on a PC.. Are you on a desktop?
wait asec. let me try to read this.
Wait wait wait.
I do not want to find the minimum value of 2 sensors.
Windows/Firefox
I can scroll - but not while retaining the selection.
variables:
sensors: "{{ expand('sensor.abc', 'sensor.xyz') }}"
actions:
- service: mqtt.publish
data:
topic: path\to\min
payload: "{{ sensors | map(attribute='state') | map('int') | list | min }}"
- service: mqtt.publish
data:
topic: path\to\max
payload: "{{ sensors | map(attribute='state') | map('int') | list | max }}"
I need to find: maximum between (room1.sensor1-room1.sensor2) and (room2.sensor1-room2.sensor2)
I do not know what that expand does
why do you need the delta... that makes no sense? You're going to have the same value... just negated
after finding the bigger difference, I need to publish that room's sensor values, sensor1 and sensor2
because the boiler will take into account the room that needs the most heating,
and the others will shut off the TRVs in case temp goes too high
It is for multi area heating.
So the device requires a delta?
Yes, the opentherm adapter works with modulation,
and needs current temperature and set temperature
and will heat the water in the installation accordingly
ok... so where does the delta come into play if it needs current temp and set temp?
that is how I know which of the rooms needs most of the heating. in case both tooms are at 15 celsius, and I only want one of them to go to 24 and the other to 20, i should publish current temp of 15 and set temp of 24
It might also work with minimum and maximum of them all if I think about it,
I get that!
but it will be a little less efficient
but what the hell do you need the delta to be published?
no no no
ok, let me explain
I do not need the delta published
You sure?
that's delta
I want to send to the opentherm controller the current and set temp temps of the room with the gratest delta.
I do not want to send the delta
what does sensor1 represent, and what does sensor 2 represent
sensor1 would be set temp, sensor2 would be current temp.
Ok, so where is the 'greatest delta for the rooms' coming from?
my point is, you don't have enough info
you'd need a sensor in 1 room. A sensor in the other, and you'd need to be able to read both of those. Then, you'd need to compare them to a desired temperature
Do you have sensors in each room?
You need to explain the whole thing not just 1 portion.
At this time the home assistant thermostat works with the sensor from one of the rooms
So you have 6 sensors? or 3 sensors and 1 target?
If you speak english ok, I can call you 🙂
na, i'm at work
I will have 3 thermostats in home assistant,
one for each room
each thermostat will publish a set temp to a dummy m1tt topic
and each room has a sensor with real room temperature
so, that'll be 3 temperatures with 3 targets
yes
the boiler should calculate its water temperature based on room temp and set temp.
OK. the automation will still be the same. But you'll have to use templates to get the desired affect.
this is a complicated template btw
hypothetically, if 2 rooms are at 24 celsius and 3rd is at 10 degrees, and I want it to go to 15, I should publish set temp of 15 and current temp of 10,
Yes I understand now
yea, some really hair pulling situations, but the correct way to do it 🙂
templates, new thing.
That's where you should start and the logic will be heavy
there's no examples because it's code.
The problem with doing this in templates is that you'll have to track which climate leads to what temperature. And it'll probably be easier if you don't make them climate devices
Isn't it easy by using different mqtt topic names?
no, not really
If i define variables: in an automation below trigger, does it work in the action too?
This template here gets you the low device. But you'll have to come up with more logic to decide what to do based on that low. Example: What happens if the low is positive in value? That means it's above the target temperature. Also, remember low_device is a state object, so to access the temperature for further logic would be low_device.state | float
{% set devices = expand('sensor.room1', 'sensor.room2', 'sensor.room3') %}
{% set targets = expand('sensor.target_room1', 'sensor.target_room2', 'sensor.target_room3') | %}
{% set ns = namespace(deltas=[]) %}
{% for i in range(3) %}
{% ns.deltas = ns.deltas + [ targets[i].state | float - devices[i].state | float ] %}
{% endfor %}
{% set low_idx = ns.deltas.index(ns.deltas | min) %}
{% set low_device = devices[low_idx] %}
If none of this jives with you... I recommend node red.
also, to get the low target...
{% set low_target = targets[low_idx] %}
if they are climate devices and not sensors... then the logic is different
you can see how having all the information affects the templates 😉
I am in the car now, and i thought of this. If i make 3 automations, each with condition AND
And there are 2 conditions. Delta room1 > delta room2 and delta room1> delta room3. Action publish room1 current to topic 1 and publish room1 set temp to topic 2
Would this work?
nope
Because there is only one solution of these 3 automations
if they are on the same update cycle, it'll be intermitten which one gets reported
it needs to be in 1 automation with 1 logic step
You can build a massive action section using the choose. Where you put all possibilities into the choose action. But it will get very complicated.
If a < b and a < c:
if b < a and b < c:
if c < a and c < b:
then each will need to find the minimum
If they are on same cycle it should be ok. If they are off, it may create intermittent responses.
Because on same cycle only one delta will be the largest, correct?
I am continuing my idea :)
home assistant is async
the only way to make them occur on the same update cycle is to have them in 1 automation
otherwise they will not be.
I understand. Did not know that
@brisk temple yes
You could do it in 3 separate automations but your conditions must be properly formatted to ensure that the action section is not run when the others are.
you'd still need templates though.
to decide which one is smaller
I just leave that here, in case someone needs it:
If you want to create a group out of your motion/window/door sensors to do some fancy stuff with it. Do the following:
- Get all sensors from dev tools/templates via
{{ states.binary_sensor | map(attribute="entity_id") | list }} - copy the list to an editor of your choice (select/sort if needed)
- replace leading spaces and quotation mark with 4 spaces, dash, space
- replace trailing quotation mark and comma with nothing
- paste into the fitting section of your groups.yaml
- reload groups
- profit
(Thanks to @ivory delta for pushing me in the right direction.)
@thorny snow you can just have it do that for you:
group:
mygroup:
{%- for bs in states.binary_sensor %}
- {{ bs.entity_id }}
{%- endfor %}
then your step list becomes:
- Get all sensors from dev tools/templates via
mygroup:
{%- for bs in states.binary_sensor %}
- {{ bs.entity_id }}
{%- endfor %}
- copy the chunk
- paste it into your group file
is it better to use entities or snapshot_entities when trying to do on-the-fly scenes? snapshot_entities is not working for me - the light doesn't return to its previous state in my automation
@torn meteor #automations-archived
Ah, interesting!
Problem for me is: This will return motion sensors, door sensors, windows sensors, etc. all mixed up. I need to sort them in some way before I can use them.
I think petro's point is that it removes the need for several of your manual edits.
You already get it formatted as a nice YAML list his way. The only manual step then is to identify which rows you want to keep 🙂
ah, so you can run that in the template editor?
You can only do it in the template editor. afaik, groups don't accept that template.
works, nice!
So I need to load a mib for a snmp OID. Anyone know where to put them so it can scan the device
what do you mean 'where to put them'?
So I have a device that has a custom MIB file. So When I create the sensor HA knows about the OID.
it is for an APC
the integrations don't use a mib file
mib files help you figure out the oid using a package that lets you scan the via snmp
Ok. So maybe I am doing something else wrong.
take this over to #integrations-archived
I have the device monitoring vian LibreNMS. This is the OID I want.
.*.4.1.3*.*.2.1 = 61```
I had posted the "full" code earlier and then I was talking snips ....
so pseudo code is: {% set i = (range(1,(t_entities|length)+1)|random) %} {% set chosen_light = (t_entities[i-1]|replace("'", "")) %} {%- if (as_timestamp(now()) - as_timestamp(states[chosen_light].last_updated) < 5) -%} *** Loop to pick a new random light and check again*** {%- else -%} {{chosen_light}} {%- endif %}
change a bunch of things
I can't figure out how to do the loop
LOL, I expect that... I am really struggling with YAML and mixing it with jinja2
you don't need a loop
I don't?
I am trying to not "randomly" select the same light over and over again...
and then ultimately I am going to not randomly set the same colour to what that light already is...
chosen_light: >
{% set lights = expand(t_entities) %}
{% set chosen_light = lights | random %}
{%- if (as_timestamp(now()) - as_timestamp(chosen_light.last_updated) < 5) -%}
no loop. Just choose a random light from your list and use it.
expand turns it into a state object
if you don't want to use expand, you can just use random on the list itself.
or, if you just want the entity_id...
chosen_light: >
{{ t_entities | random }}
either way, seems like you're over complicating it
ok, that is a simpler way of selecting a light. but it fundamentally change which light is selected from my more convoluted way of doing it... but when I run this it will change light1, light2, light1, light1, light4, light3, light1 .....
and I want it to pick a different light if the one chosen has changed in the last 5 seconds...
then you need a placeholder to store the last light
so that it appears more consistent to someone viewing the lights that they are changing..
right, I could use a placeholder, or the last_updated time, but I still need a loop right?
This sounds like exactly the kind of thing that would benefit from an actual Python script instead of a template.
I think I need to loop until I select a light that isnt the last light, or the selected light hasn't changed in 5 seconds (or 10 seconds haven't decided yet)
A simple way would be to have a list that doesn't include the current light, then randomise.
I should step back for a second so that Mono and Petro know what I am doing... Every 2 seconds I am calling this script to change the light colour.. which is working fine, but what I am trying to improve now is to not pick a light that has already changed in the last 5 seconds and to not change it to the colour it already is.
so the current light doesn't really work, cause it would be the last two lights if I decide on 5 seconds, or the last 5 lights if I decide on 10 seconds
{% set lights = expand(t_entities) %}
{% set t = now() - timedelta(seconds=5) %}
{{ lights | rejectattr('last_updated', '>', t) | map(attribute='entity_id') | list | random }}
had to adjust it, i think it should work
might want to do 6 seconds if your changing it every 5 seconds
for the timedelta
Hey @mighty ledge , are you still around?
I am working with your suggestion and have it in my code like: https://paste.ubuntu.com/p/b48k8QBTKy/
this throws the error: ```Logger: homeassistant.components.script
Source: helpers/entity_component.py:283
Integration: Script (documentation, issues)
First occurred: 1:48:33 PM (1 occurrences)
Last logged: 1:48:33 PM
invalid key: "OrderedDict([('chosen_light', None)])" in "/config/scripts.yaml", line 31, column 0```
but if I comment out lines 29 -> 32 it works fine (selects a light and colour, and writes it to the log).. how can chosen_light not be found 3 lines later?
im trying to hunt - is there a way to make a template read occurrence in x time
I have a counter and if that resets 2 times in 5 mins i want to run an automation
Petro, never mind... I found my issue... I need to enclose the {{chosen_light}} in ' '
sorry was driving
no worries, just debugging now... I am changing the light colours, but it doesn't appear like it ignoring ones that have recently changed...
wait, testing again... seems to be working.... 😕
nope... still repeating lights within the 15 seconds... (I changed to 15 seconds and am using a 3 second trigger, so in theory it should update 5 lights before repeating)...
2020-12-21 14:22:27 WARNING (MainThread) [homeassistant.components.system_log.external] ('15 second catch >:', 'light.driveway_2', 'red')
2020-12-21 14:22:30 WARNING (MainThread) [homeassistant.components.system_log.external] ('15 second catch >:', 'light.01401742cc50e3e1b6fd', 'green')
2020-12-21 14:22:33 WARNING (MainThread) [homeassistant.components.system_log.external] ('15 second catch >:', 'light.driveway_2', 'red')
2020-12-21 14:22:36 WARNING (MainThread) [homeassistant.components.system_log.external] ('15 second catch >:', 'light.014017422cf43280c9ac', 'blue')
2020-12-21 14:22:39 WARNING (MainThread) [homeassistant.components.system_log.external] ('15 second catch >:', 'light.driveway_2', 'green')
2020-12-21 14:22:42 WARNING (MainThread) [homeassistant.components.system_log.external] ('15 second catch >:', 'light.014017422cf43280c9ac', 'red')
2020-12-21 14:22:45 WARNING (MainThread) [homeassistant.components.system_log.external] ('15 second catch >:', 'light.driveway_3', 'red')
2020-12-21 14:22:48 WARNING (MainThread) [homeassistant.components.system_log.external] ('15 second catch >:', 'light.underdeck', 'red')```
that is a subset of the logs put out, and as you can see the light ending in 9ac is changed at 22:36 and 22:42 and driveway_2 is changed at 22:27, 22:33 and 22:39
https://paste.ubuntu.com/p/ctRH7JpCpq/ is the current copy of the code
is it possible that last_updated is not the attribute I want to be looking at?
Is there a best practice when deciding when to use float as part of a template sensor?
how could I make a template sensor that returns the entity id of the most recently updated out of a list of entities?
@true otter , Integers and floats are two different kinds of numerical data. An integer (more commonly called an int) is a number without a decimal point. A float is a floating-point number, which means it is a number that has a decimal place. Floats are used when more precision is needed.
Is it possible to check if all/some objects in a domain are of a specific state with templates? Basically want a {{ is_state('states.person.state','not_home') }} that will automatically check the state of all person objects. Kinda like a group, without needing to group.
Can I add a template to my device before flashing to 9.2.0 from 8.5.1 ?
Something like this?
{{ states.person | selectattr('state', 'equalto', 'home') | map(attribute='entity_id') | list | count > 0 }}
Flip the equality check and the zone names as needed... but that'll return True when the count is greater than 0.
In fact, you can simplify it further by removing the | map(), since you don't care about getting any details.
@blazing burrow
{% set entities = expand(LIST OUT ENTITIES) %}
{% set last_ts = entities | map(attribute='last_updated') | list | max %}
{{ (entities | selectattr('last_updated', 'eq', last_ts) | list | first).entity_id }}
oh it works
I think you need to expand on your question. This channel is for templates and flashing devices is not required for any template unless the template is specific to an integration. And if that's the case, then you want to ask your question in #integrations-archived and include the integration you're asking about.
Oh wait.. Sorry, I got confused on templates and software.. Tasmota is what I am referring to, so that has nothing to do w/ anything here, so disregard my question.. When I asked that, I was running on 4 hours asleep in the last 48 hours.. I've gotten some sleep now, and my confusion has cleared..
morning, all. the peloton sensor i'm using stores an image URL in one of the attributes. how can i get that image into a card? my suspicion is that i need to use a template, but i am wildly unfamiliar with them
googles didn't turn anything up 😦
It depends on the card, since the native ones don't support templates.
You can either use this to add templates to native cards (https://github.com/iantrich/config-template-card) or use a custom card that supports templates already.
But yes... you can use a template to read the attributes of an entity: {{ state_attr('sensor.peloton', 'picture_url') }}
Update the names to suit 🙂
thanks @ivory delta. it's not clicking for me yet, but i'll keep playing with it
@haughty kiln their github has examples of the markdown template: https://github.com/edwork/homeassistant-peloton-sensor/tree/master/examples
thanks@brisk temple
anyone that could help see why my attributes aren't being filled here? https://pastebin.com/1fxEjC84
my response looks like the one in the "mqtt" section here: https://github.com/blakeblackshear/frigate/blob/release-0.8.0/README.md
@blazing burrow you have to template each field. json_attributes_template does not accept templates, child fields do
json_attributes_template:
camera: "{{}}"
start_time: "{{}}"
label: "{{}}"
Hello. I would like setup a template to open blinds in sequence with a set delay in between. This may not be the best approach using a template. Basically, I would like to have single cover entity to control 4 blinds with a delay in between. I did try grouping them together, which works but I’m afraid that I will have communications conflict.
@hollow rampart that's an automation
delays cannot be performed in templates.
but if you're referring to the template cover integration, then you should be in #integrations-archived
Ok thank you!
@mighty ledge that is described completely differently in the docs 😅
"MQTT Sensor - Home Assistant" https://www.home-assistant.io/integrations/sensor.mqtt/
ah, I had forgotten to tojson filter anyways 😅
Where does it describe what you're talking about?
That's new functionality then
and doesn't show anywhere like this
Look at the history, it used to be like that
either way, you have it sorted out aparently
it most likely extends from the data field so templates are now allowed at the root level or internally
Hi! I use this template sensor to see how many active connections my emby server has.
But i also want it to include 'paused' state not only 'playing'. So if 1 is playing and one paused value should be 2 🙂 Anyone knows how ? 😄 :
{{ states.media_player | selectattr('state', 'eq', 'playing') | rejectattr('attributes.server_name') | list | count}}
What other states can it have?
If there's only one other possible state, go with | selectattr('state', 'ne', 'theotherstate')
Otherwise, chain a few | rejectattr() together to eliminate the ones you don't want.
for LIST OUT ENTITIES, should they just be comma separated, or inside [ ]?
If they're not comma-separated, they're not a list...
toffee apples
toffee, apples
that's what I thought lol I'm not familiar with expand(...)
but my question is more about the brackets
does expand take multiple args, or a single list arg?
A single list
Mmmm, toffee apples....
Holy heck that's tricky! Jinja is bloody cool 😄
Doesn't matter. Pass a list or list them inside the ().
expand is pretty smart. If you pass expand(a, b, c, d) it will return a list of state objects [ a, b, d, d ]. Same as if you pass it as a list expand([a, b, c, d])
its possible to pass a variable to a script. How do I check for the sole existence of that variable in the script? Or is there any other sleek way of preventing the script to throw an error if the variable isn't set? 🙂
im trying to hunt - is there a way to make a template read occurrence in x time
I have a counter and if that resets 2 times in 5 mins i want to run an automation
{% if myvariable is defined %} ?
whats the shorthand for a condition for this? Can I get away with not having the entire if else syntax?
i put it in the script so not every automation needs it
only used it for lights
so i can pass brightness or transition from the automation if wanted, otherwise the script defaults in the else of the template
- service
- condition: " ... "
- service
nice idea
@mighty ledge this one doesn't seem to be giving me the latest updated... unless I'm missing something 🤔 https://pastebin.com/hdnBPV0J
it should, works for me
ooh you know what
frigate updates all of them every time around
so it is, but they're all getting updated with the same (or close) time
Hi, I'm having some issues with a template switch? I'm trying to combine two switches into one on/off switch
I can get the switch.erv entity but i can't seem to trigger the 'turn_on' or 'turn_off'
@little field posted a code wall, it is moved here --> https://paste.ubuntu.com/p/nDM4cYSctw/
im on version 2020.12.1
@little field I can’t exactly follow your intended actions here. You’re turning on/off an Input Boolean, and then toggling switch entities that are associated with on/off.
What is your use case, and why can you not just use the Input Boolean and a couple automations instead of a template switch?
@inland hazel I have two switchbot bots that is on either end of a rocker switch that controls my ventilation . I could turn them into an automation but I'd much rather merge the two bots as one single entity controlled by input_boolean toggle. I've tried without the "service: input_boolean.turn_on data: entity_id: input_boolean.erv" bit but both scenarios didn't work. Not sure what the correct syntax is and figured i'd just leave it in there.
Edit: I misunderstood what the value_template did. I've figured it out. switch.erv is working, but input_boolean does not trigger switch.erv (which i thought value_template would accomplish via state change).
Hello, is this templating correct?```
- payload: template
- value_template: "{{ max: states('sensor.dummy-t2-r2')|float; states('sensor.dummy-t2-r1')|float }}"
It should spit out the highest value of the 2 sensors.
Checked it by dev tools, and looks like the correct syntax should be
"{{ max, states('dummy-t1-r1')|float, states('dummy-t2-r1')|float }}"
It is not good,
Got it: "{{ (states('dummy-t1-r1')|float, states('dummy-t2-r1')|float)|max }}"
Hello, when im creating a light template and want to configure the "set_color" action, are the 'h' and 's' variable the only ones which were deliverd or is there a way to grab the R, G,B values of the "Change" ?
victron
I'm working with a climate | mqtt platform when I trigger the device for off I'm expecting a 0 in mqtt because I have the payload_off: 0 set. But if sends off. any ideas
power_command_topic: "aqualinkd/Pool_Heater/set" payload_on: "1" payload_off: "0"
@calm sundial posted a code wall, it is moved here --> https://paste.ubuntu.com/p/YDm8Yqjt9g/
@calm sundial It looks like you're trying to provide a list of templates, when only a single template is expected. Also, templates should be quoted unless a block is defined. Can you test this and see if it works out for you? https://hastebin.com/ucifevogiz
Yep, that was it! Thanks!
What is wrong here : https://del.dog/praithasto.txt
Expected <block end>, but found ‘<block mapping start>’
is state ≠ is_state
I have to remove the _?
You have four is_state but they aren't all written the same
it's supposed to be is_state(
Oh lens added spaces
your second value template also has spaces
It's also better this way states('sensor.luxtronik_id_web_analogout2_2') so everything is more consident
And single quotes
It's an old template that was only available as a screenshot
Do I replace the entire thing inside {{ }} with that ?
I mean up to the |
Oh my model doesn't have that function
So I'll delete
It was just for th second sensor you had
It turns out my device doesn't support that one
Then no issue
it's the same thing
just two different ways of writing it
NOt sure what the difference is. I just had people tell me that second one is better
I don't actually know why haha
if i have an array of dicts, is there a way to get a value from each element of an array?
i see a lot of examples of using the index value ([0], [1]) but nothing that will let me get all of a single key. for example, all of the id values from an array of dicts
or let's try it another way
{{ states.sensor.adhan_tracks.attributes['items'] | random }} this returns a dict
i want to now get a singular value out of this dict
do i have to do it separately like this:
{% set x = states.sensor.adhan_tracks.attributes['items'] | random %}
{{x.id}}
Hi everyone. i have a automation in which i want to use a slider to change the brightness of my lights. For some reason i get the error:
Mancave brightness aanpassen: Error executing script. Invalid data for call_service at pos 1: expected int for dictionary value @ data['brightness']
im using this template:
- service: light.turn_on
entity_id: light.mancave_lampen
data_template:
brightness: >
'{{ (states("input_number.mancave_brightness") | int) | round(0) }}'
could someone help me out. In the devtools the {{ (states("input_number.mancave_brightness") | int) | round(0) }} gives a perfect round number
nm. i fixed it myself eventually. the ' in front and ' behind should be removed.
I'm trying to turn on a boolean when my robovac is docked but only if it has been cleaning for a minimum of 1 min. I have this so far... https://pastebin.ubuntu.com/p/H38Pp4xFWy/ (note the conditions) but does not work. Does anyone know a template that will know when something has ran for >1min in the last 24 hrs.
i have this code: {% if is_state('input_number.mancave_brightness', '25') -%}but what i want is to check if this value is "<= 25" how do i write this in an if statement template?
@fast mason how do I make android/discord not lose the yaml formatting
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/.
Mother of god
- platform: template
sensors:
delta_t:
friendly_name: "Delta T"
unit_of_measurement: '°C'
value_template: "{{ states('luxtronik.temperatuur_aanvoer')|int - states('luxtronik.temperatuur_retour')|int }}"
device_class: "temperature"
Is this exactly what you have ?
Cos indentation is wrong in what you are showing me
- platform: template
sensors:
delta_t:
friendly_name: "Delta T"
unit_of_measurement: '°C'
value_template: "{{ states('luxtronik.temperatuur_aanvoer')|int - states('luxtronik.temperatuur_retour')|int }}"
device_class: "temperature"
And I am assuming you only have this once
- platform: template
sensors:
Hmm weird
For android? I have no idea
Best would be to use vscode since that has a lot of plugins for yaml
I'm having a hard time grabbing the id value out of this resulting dict
The code works but the way
{
"id": 10,
"title": "Ahmad Al Nafees",
"title_sort": "Ahmad Al Nafees",
"artist": "Adhan",
"artist_sort": "Adhan",
"album": "Adhan",
"album_sort": "Adhan"
}
this dict is created by doing: {{ state_attr('sensor.adhan_track', 'items') | random }}
i've tried {{ state_attr('sensor.adhan_track', 'items') | random | selectattr("id") } but the devtools just shows me <generator object select_or_reject at 0x7f2376d8a510>
this seems to work fine
value_template: >
{% set track = value_json['items'] | random %}
{{ track.id }}
I'm having trouble formatting datetime in a template, somehow the online topics on this won't work
online examples work with sensors, using a value_template property, I work with an entity, which seems to ignore that property
entity: sensor.voordeur_last_ding
name: Laatste keer aangebeld
value_template: >-
{{ as_timestamp(sensor.voordeur_last_ding) | timestamp_custom('%D %-I:%M %P')
}}```
Can anyone tell me the correct syntax to have this work with an entity card
okay I got it. template needs to be defined in configuration.yaml, after that I can reference the template in my frontend.
hi !:) rest sensors cannot introduce icon_template? [sensor.rest]: [icon_template] is an invalid option for [sensor.rest].
Why is this template not working?
{{ is_state_attr('media_player.mibox3', 'app_name', 'YouTube') }}
{{ state_attr('media_player.mibox3', 'app_name') == 'YouTube' }}
{{ state_attr('media_player.mibox3', 'app_name') }}
The latest does show "YouTube" but the two above stay false
Result type: string
False
False
YouTube
(I'm in the template editor)
Is there any way to get this into one template? I want to have a running time for my robovac shown. It looks like i have to do. it in two. One to get the running time and two to make it readable in time... https://pastebin.ubuntu.com/p/XPZKhwQNgY/
Here I have multiple sensors for my vaccum, and one of them is how long it took for it in the last cycle, is that what you want?
https://github.com/yuvalabou/HomeAssistant-Config/blob/master/homeassistant/config/integrations/sensor/vacuum.yaml
@granite steppe
I use it to notify me how long it took for last cycle and how much it covers in meters
Thanks.. thats helpful. I'm looking for a time stamp in hh:mm of how long the vac has ran today which resets at midnight. I am them looking to integrate it into a an automation to turn on a boolean only if the vac has been running more than 15 mins each day
@native pilot
If that is your main goal you don't need a template to achieve that
Line 49
And also the reset automation is there
@granite steppe
Thanks. I might do that. I try to merge a lot of automations together into one so that i dont have 100's of notifications in the UI haha
Obviously this is a goal. Just lately I have combined a lot of sensors and automation.. last couple of update greatly helped
these two templates do basically the same and should update every minute right? -->
{{ ((as_timestamp(states('sensor.cert_expiry_timestamp_cvoid_de')) - as_timestamp(states.sensor.date.last_updated)) / 86400) | int }} {{ ((as_timestamp(states('sensor.cert_expiry_timestamp_cvoid_de')) - as_timestamp(now())) / 86400) | int }}
thanks
Hello
friendly_name: "Consumo Total Actual"
value_template: "{{( states.sensor.shelly_shem_1_current_consumption.state)|int + (states.sensor.shelly_shem_2_current_consumption.state )|int}}"
device_class: power
Why is not returning properly?
The final value i belive is text
So it does not format xx.xxx W
But xxxxx only...
Also shows a bar graph instead of line graph on history...
What am I doing wrong?
when using "days" as unit of measurement is there anything that I could use for the frontend to be autotranslated to the browsers set locale?
like en_US 21 days and 21 Tage when e.g. de_DE is set?
If you're specifying the unit of measurement, probably not.
You could pick any word/symbol/abbreviation for a unit - HA can't know how to translate them all.
There will be ways to template the units in your #frontend-archived using custom cards.
👍
If you are dyslexic your username @steep kiln spells a disease 😮 I really got taken aback for a few seconds there
Hi all. Newbie here. In the example "value_template: '{{ value_json.value.state }}'" to extract a value from a json output is defining this the actual template itself or do value_template and value_json have to be defined somewhere first before being referenced?
I have two devices (light switch) that each have 3 potential triggers (turn_on, turn_off, dim_up). I have them all listed as triggers in an automation. However I'd like the action to be dependent upon the the device that fired the action. Basically if trigger is from device 1 then the action should be for bulb 1. Device 1 turn_on Bulb 1, Device 2 dim_up Bulb 2
I see I can do conditionals as posted here: https://community.home-assistant.io/t/automation-if-else-is-that-possible-in-one-automation/83466/3
but I'm not quite sure I am wrapping my head around how to accomplish the conditionals I'm looking for
https://hastebin.com/kinekerafo.yaml can someone take a look at this? This is my first template and something isn't quite right but I can't put my finger on it
I'm not sure if what I am trying to do with the if in the service area is possible
@fast mason well... it was always chrisvoid (short cv..) but this stupid flu came after me 😉
I'm trying to convert temperature data which comes from an MQTT sensor and which looks like xx.xx C into a numeric value.
I tried value_template: "{{ value_json | from_json | regex_replace(' C', '') | float }}"
But it doesn't look like it works ("unknown")
any clue?
Oh, using value instead of value_json | from_json seems to do it
This sensor gives me the value of "2:07:23", how can I display this whitout the ""?
- platform: rest
name: Glances - DeCONZ - Uptime
resource: http://10.0.24.11:61208/api/3/uptime
This is just a value, no label in api,
Something like this {{ x.split('"')[1] }} would make it into a list (splitting at the double quotes) and take the second item (the value between the quotes).
Swap out x with your actual sensor.
I think I might do it wrong @ivory delta ?
- platform: rest name: Glances - DeCONZ - Uptime value_template: {{ glances_deconz_uptime.split('"')[1] }} resource: http://10.0.24.11:61208/api/3/uptime
This worked:
value_template: '{{ value_json }}'
So the value doesn't have quotes 🤷♂️
nop, but it was displayed with quotes in if it was no value_template
@autumn hemlock , your trigger.entity_id is a sensor which you are using to trigger off of, then you are trying to turn it off/on
Yeah I realized my setup probably won't work because the trigger needs to adjust a different device
It's a switch that controls a light bulb
@wispy bane posted a code wall, it is moved here --> https://paste.ubuntu.com/p/DTftdpqwKF/
@autumn hemlock Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
Sorry, @autumn hemlock , that was @wispy bane
my bad guys.
Posts happen so quickly
Didn't realise there was a limit on the size of the post. I guess it makes sense
@autumn hemlock , you can in fact do what you are trying to do you just need a some what advanced template
You need to define the entity_id in an if elif statement according to the trigger entity.
perfect, i think i can go from there
Hi guys, do I post the link aut-generated by HassBot? I don't want to spam the channel
yes, it appears to link your code for you
though you could only upload your code and then post your question (since it took your entire post and put it in the link)
I'm having an issue with getting a value from a json output. Would be grateful if you could take a look and let me know what's wrong
https://paste.ubuntu.com/p/DTftdpqwKF/
@wispy bane , you posted information with values != unavailable and then said your device is unavailable. Do you need help with the actual sensor or templating it’s attributes? Cause the first should be moved to #diy-archived or #general-archived
I need help with the template so that I can extract the temperature from the json output
Not sure why the device is showing as unavailable. Thought it might have something to do with why the value is not being extracted.
Could you test without the availability part? You set an availability topic, are you sure the Online has been sent on the topic to make the sensor available?
Yes. "tele/zbBridge/LWT" is "Online". Will try without the availability topic
It works. Thank you. I thought my template was wrong.
Now I need to figure out why the availability isn't working 🙂
Here's the Log entry for the messages received for tele/zbBridge/LWT
2020-12-28 14:25:01 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on tele/zbBridge/LWT (retained): b'Online'
Could you try to use availability_topic: instead of
`availability:
- topic:
`
?
Do I need to specify "payload_available" and "payload_not_available"?
yes
It works. Thank you so much
Ok so I realized I needed to change the triggers (for better or worse) and I think I needed to switch to a data_template as the action. The one thing I am unclear on is how to act on a subtype, ie type: remote_button_short_press, subtype: turn_on, in the data_template area https://hastebin.com/aqilezeyes.yaml
when I add the switches (sensors) in the automation UI it adds it as with a device_id and domain: zha. I read that I can omit those and replace it with the entity_id, is that correct?
I don't really understand why in the example given in the integration page https://www.home-assistant.io/integrations/sensor.mqtt/ they use the notation you were using before, while in the CONFIGURATION VARIABLES section, the use the notation I suggest... An issue in the doc I guess. If anybody here knows how to adapt the doc 🙂
oddly enough I had tried the one you suggested previously and it didn't work. I must have done something wrong then. The good thing is that it works now but you're right updating the documentation is probably a good idea.
@autumn hemlock data_template is not an action, you can't put that directly under action:
you have to use - service: "{% your template to choose light.turn_on or turn_off %}"
action:
- service: "{% your template to choose light.turn_on or turn_off %}"
data:
entity_id: "{% your template to choose your entity_id %}"
it is not viable code. I see a lot of issue in your code... you can not put the template at a new line like that, you have to use >
and are you sure your entity_id are lamp.* and not light.* ?
I don't know the domain lamp
you are totally correct, let me do another pass so i dont waste your time
subtype can't be use as you do, for sure
though I don't know how to get it, if possible
crap haha, i feel like that probably halts my progress
unless i want to try to do conditionals based on the current state/brightness of the bulb
{% if trigger.entity_id === sensor.isabellesroom_switch %}
should be
{% if trigger.entity_id == "sensor.isabellesroom_switch" %}
https://hastebin.com/ratamafosa.yaml so this should be "good" and now I just need to figure out how to get the subtype
you still need to change === with ==, and put quotes around the texts
brightness: >
{% if subtype === turn_on %}
brightness: 25
{% elif subtype === dim_up %}
brightness: 255
{% endif %}
with ```yaml
brightness: >
{% if subtype === turn_on %}
25
{% elif subtype === dim_up %}
255
{% endif %}
well yes
basically everything that is on the right side of your == in your code
right right, i wanted to clarify you didnt mean brightness or service values
(unless in a conditional)
Hi, I am new to home assistant, I have installed it on a PI4 and I need some help
I tried almost all day to make it work
I have a tp link router and there are some entities that display bytes sent and received in bytes
I would like to show in MB and I tried to do it using template.
i have this entity
sensor.tl_mr6400_kib_s_received that has the following attributes:
unit_of_measurement: KiB/s
friendly_name: TL-MR6400 KiB/s received
icon: 'mdi:server-network'
and the "state" is the total bytes received.