#templates-archived

1 messages · Page 97 of 1

trim leaf
#

The "state" here doesnt even say what unit it is

#

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

inner mesa
#

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?

trim leaf
#

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

inner mesa
#

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

trim leaf
#

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

inner mesa
#

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

trim leaf
#

Alright let me give this a shot. Thanks a ton for the help!

inner mesa
#

np, good luck. come back with any questions

silent barnBOT
urban turret
#

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?

silent barnBOT
arctic sorrel
#

Which bit isn't working?

urban turret
#

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 ?).

hexed galleon
#

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"```
urban turret
#

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!

arctic sorrel
silent barnBOT
#

YAML is the mark up language used by Home Assistant, consistent indenting (two spaces per level) is key. Here is a primer, and this explains multi-line templates. For validating YAML see YAML Lint.

arctic sorrel
#

And there ☝️

#

Indenting - those spaces - is critical in YAML

urban turret
#

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

jagged obsidian
#

visual studio code or sublime text

urban turret
#

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

jagged obsidian
#

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

urban turret
#

Thnx! VSC it will be

snow zenith
#

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 ?).

silent barnBOT
snow zenith
#

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 %}
silent barnBOT
#

@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.

snow zenith
#

you figured it out, you needed quotes around that last bit

soft bough
#

me? yea i noticed i was mixing ' and " inpropperly

snow zenith
#

yup

rich stag
#

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
brisk temple
#

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

arctic sorrel
#

Easy 😉

brisk temple
arctic sorrel
#

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

brisk temple
#

Thanks, I'll play with the else

#

thanks error went away

rain pebble
#

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?

brisk temple
#

i think your or is goign to need () around both is_states

#

both is_states meaning the first 2

hollow bramble
#

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)

rain pebble
hollow bramble
#

Almost

#

first parenthesis has to go in front of is_state

rain pebble
#

That seemed to do the trick. Thanks guys

opal dawn
#

Evening guys. Could use your help with some automation templating....

silent barnBOT
ivory delta
#

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.

opal dawn
#

Switch on something when a read out humidity is below 95 for 10 minutes between a certain setup time

ivory delta
#

Between what times?

opal dawn
#

should be after 21:00 and untill 06:00 in the next morning

ivory delta
#

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.

opal dawn
#

Correcto

ivory delta
#

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'

silent barnBOT
#

@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.

opal dawn
#

Yes

#

thats the right explanation

ivory delta
#

So you want a template that checks for 'not between 6am and 9pm'.

arctic sorrel
#

Or is either before 6 am or after 9 pm

ivory delta
#

Your templates aren't the problem, your logic is.

opal dawn
#

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

ivory delta
#

Not complicated. See Tinkerer's answer.

arctic sorrel
#

If the times are fixed, a time condition will do it

ivory delta
#

It's tempting to come up with a complex answer to a simple problem if you don't understand it clearly.

opal dawn
#

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

ivory delta
#

You can... just make it 'or' instead of 'and'.

opal dawn
#

I need to let that one sink in

ivory delta
#

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 😉

opal dawn
#

you right 😉 but I my second template part didnt give me the desired result heheh

still harbor
#

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.

buoyant pine
#

.share the sensor config

silent barnBOT
still harbor
#

@buoyant pine I'll have to do this when I get home. Thanks!

spice abyss
#

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.

buoyant pine
#
"{{ state_attr('input_datetime.coffee_time', 'hour') }}"
#

similar for minute

spice abyss
#

You have double quotes around it instead of single quotes, is that important?

buoyant pine
#

i have double on the outside because i'm using single on the inside

spice abyss
#

Ill give it a shot!

#

Brb

buoyant pine
#

also, to explain, input_datetime entities have state attributes for hour, minute, etc.

spice abyss
#

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...

buoyant pine
#

you can always look at developer tools > states

spice abyss
#

So anything that shows up there is accessible?

buoyant pine
#

yeah

spice abyss
#

Thanks! let me restart and we will see what happens.

still harbor
#

@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

buoyant pine
#

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
silent barnBOT
still harbor
#

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!

buoyant pine
#

Caught me just in time--I've been putting my phone on silent every Friday night starting at 19:30. Four minutes away 😄

spice abyss
#

@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?

buoyant pine
#

You can reload those at configuration > server controls regardless of where they're at in your config files

#

Same with everything you see there

spice abyss
#

I don't see them there

RELOAD LOCATION & CUSTOMIZATIONS
RELOAD GROUPS
RELOAD AUTOMATIONS
RELOAD SCRIPTS
RELOAD SCENES
RELOAD PERSONS
RELOAD ZONES
analog finch
#

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.

https://imgur.com/a/odb7BlO

link to the template switch snippet from my config
https://paste.ubuntu.com/p/HjNhdNDZPp/

hollow bramble
#

What does the value_template that you have commented out render as?

fathom compass
#

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?

analog finch
gusty nimbus
#

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

ivory delta
#

Use the command line checker, not the one in the UI.

silent barnBOT
#

Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.

lavish mantle
#

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?

https://templates.blakadder.com/TYMC-1.html

arctic sorrel
#

Tasmota supports auto-discovery though, so I'd start there

lavish mantle
#

Okay thank you. I doubted between integrations and this channel

timid osprey
#

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

inner mesa
#

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.
timid osprey
#

"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."

inner mesa
#

that's true, but you were asking about the icons

timid osprey
#

yeah, it affects icons and such too

inner mesa
#

you sure?

timid osprey
#

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*

inner mesa
#

set it to some random value?

#

point being that I don't think there's any comparison being done

timid osprey
#

just read your last message, was restarting to show this

inner mesa
#

ok. make it "foo" and see what happens

timid osprey
inner mesa
#

interesting, I guess I'm wrong

timid osprey
#

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!

inner mesa
#

time to dig into the source

inner mesa
#

thanks! was looking for where the translation from that to icon takes plae

timid osprey
#

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.

inner mesa
#

I'm glad you brought it up because I didn't think it mattered at all

timid osprey
#

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.

inner mesa
#
  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

timid osprey
#

thanks

#

so I can set device class and get those cions at the top

#

perfect

inner mesa
#

so it seems

timid osprey
#

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

inner mesa
#

touch ui_lovelace.yaml

timid osprey
#

yeah :/

inner mesa
#

it's a pain

#

I avoid includes for the stuff I usually change

timid osprey
#

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

inner mesa
#

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

timid osprey
#

yeah, not using any anchors atm

inner mesa
#

that's another annoyance. otherwise, I'd have an include file with my anchors

timid osprey
#

what are you using yours for?

inner mesa
#

mostly styles

#

for card_mod

timid osprey
#

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

inner mesa
#

custom cards like button_card avoid the need for card_mod, but not for everything

timid osprey
#

lol

inner mesa
#

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

timid osprey
#

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

inner mesa
#

Yep

#

I’m sure the community would appreciate a doc PR that describes it all 🙂

violet oyster
#

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')

buoyant pine
#

@violet oyster extract the day from the timestamps and find the difference between those

violet oyster
#

would that work across different weeks? like if today is saturday would tuesday show +2 or -5

#

or do you mean date

buoyant pine
#

Date, yeah

violet oyster
#

ok good idea. ill give it a shot

buoyant pine
#

Like, 25 - 23

violet oyster
#

even then i wonder if it would work across months

buoyant pine
#

Ah shit lol

#

Just woke up, my 🇧

violet oyster
#

every way i think about it i hit a roadblock lol

buoyant pine
#

Well, you could still find the difference in seconds and use templating to determine the number of days based on that

violet oyster
#

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

mighty ledge
#

@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.

mighty ledge
quiet kite
#

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

violet oyster
#

@mighty ledge Thank you!!!!!

gray wharf
#

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.

violet oyster
#

why not just copy and paste to make the extra template sensors?

gray wharf
#

cause it's a very long template. and maintaining it could be a pain.

violet oyster
#

i cant think of a way to do that without writing a python script or something

arctic sorrel
#

You can't "template" template sensors I'm afraid

violet oyster
#

you couldnt create 5 entities from one sensort

arctic sorrel
#

You could use YAML anchors

silent barnBOT
#

YAML has a handy feature called anchors, which let you easily duplicate content across your document

violet oyster
#

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.

gray wharf
#

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?

arctic sorrel
#

You can define a variable before the anchor though, and use that variable

violet oyster
#

@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

gray wharf
#

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
#

?

arctic sorrel
#

Should be

#

I've never done it, but the theory is good

gray wharf
#

hmm i will try but my gutt says no 🙂

violet oyster
#

@gray wharf you should see my config. youd cry a river

arctic sorrel
#

Fortunately we're not listening to your gut 😉

violet oyster
#

im over 10k lines

#

unwieldy to say the least

gray wharf
#

nope @arctic sorrel not working.

arctic sorrel
#

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

violet oyster
#

how many commented out lol

arctic sorrel
#

You can't anchor over multiple files

rugged laurel
#

8 lines here

gray wharf
#

theyr're in the same file.

arctic sorrel
#

About 1K 😄

#

(but many of those will be comments explaining what it's doing)

violet oyster
#

lol

rugged laurel
#

This does "something"

violet oyster
#

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

lapis quarry
#

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 😅

hollow bramble
#

you just did paste it

#

the correct way even

arctic sorrel
lapis quarry
#

😀

arctic sorrel
#

New poster ✅
Follows rules ✅

hollow bramble
#

Which template are you having trouble with? There are several there

dreamy sinew
#

all the mods need to take a drink now

#

lol

lapis quarry
#

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

hollow bramble
#

Just add an elif to cover the condition

lapis quarry
#

that is what I have been trying but cant seem to figure it out

#

😅

hollow bramble
#

first I would check the inputs against each other to figure out which one is earliest

lapis quarry
#

not sure I get what you mean

hollow bramble
#

{% if states('input_datetime.room03_ac_timer_on').rsplit(':',1)[0] < states('input_datetime.room03_ac_timer_off').rsplit(':',1)[0] %}

lapis quarry
#

ok

hollow bramble
#

Oh oops, I forgot to change the logic between the two, but hopefully you see the idea

lapis quarry
#

yes I think that makes sense

#

awesome, let me tinker with it I will let you know if I can get it to work 😄

hollow bramble
#

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') }}

lapis quarry
#

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

#

🤣

hollow bramble
#

Luckily the dev tools template editor makes the "guessing" method very easy

lapis quarry
#

yes

#

would never ever have succeded to use templates without that

#

😅

hollow bramble
#

I mean for doing it all on your own you got 99% of the way there. That's very impressive

lapis quarry
#

thanks but its mostly copy paste and a lot of trial and error

#

😅

hollow bramble
#

You just described almost any modern programming job

lapis quarry
#

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

hollow bramble
#

and now you know where to find us for further assistance 👍

lapis quarry
#

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?

buoyant pine
#

YAML anchors if everything is within the same file

lapis quarry
#

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

buoyant pine
#

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 %}
hollow bramble
#

"simplify" 😱

buoyant pine
#

@lapis quarry might want to make an exception for this. YAML anchors could be a big help here

hollow bramble
#

You could also get clever with the template, but it could get really complicated really quickly

lapis quarry
#

@lapis quarry might want to make an exception for this. YAML anchors could be a big help here
@buoyant pine What is that about

buoyant pine
#

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

lapis quarry
#

everything?

buoyant pine
#

everything that uses this same template

#

any automations that you want to use the anchor/alias with, rather.

lapis quarry
#

The way I ahve it is I have a file with the 20x input_datetime.roomXX, another file with the 20 switches, etc..

buoyant pine
#

packages

#

wait, that doesn't matter. i'm just talking about the automations

#

are all 20 automations in the same file?

lapis quarry
#

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

buoyant pine
#

right, so anchors/aliases would work for you then

lapis quarry
#

It would be awesome for maintenance and future upgrades, its a nightmare to mantain and modify now

#

😭

buoyant pine
#

anchors and aliases

lapis quarry
#

jaja

buoyant pine
#

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

lapis quarry
#

I see

buoyant pine
lapis quarry
#

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

quiet kite
#

hey

lapis quarry
#

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

quiet kite
#

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)}}

lapis quarry
#

waste

buoyant pine
#

@quiet kite share the config for the mqtt light

silent barnBOT
quiet kite
buoyant pine
#

good lord

quiet kite
#

😭

lapis quarry
#

need to get some rest, 1 am here, will be back tomorow, thanks for all the help guys much apreciated 😄

buoyant pine
#

i'm not saying it's wrong, i was just overwhelmed by the number of lines lol

quiet kite
#

I think so

#

But i must write few additionals lines, for example support for getting colour state...

buoyant pine
#

the math looks fine, but you might need to convert white_value to a float and then the result to an int

quiet kite
#

So isnt simplest method to scale?

#

, "22": {{ (white_value|float * (1000/255))|int}} ?

buoyant pine
#

looks fine, but i don't know for sure if you can use templates there

quiet kite
#

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

haughty briar
#

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 }}'   
dreamy sinew
#

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

haughty briar
#

i solved it like this: {{ states('sensor.canon_ts5000_series_magenta') != 'unavailable' but it's additional code 😕

carmine aspen
#

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

buoyant pine
#

What are you trying to do?

carmine aspen
#

I have a message that I want to send if the state of my garage door has been closed for 2 hours

buoyant pine
#

State trigger with for: '02:00:00'

carmine aspen
#

{% 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?

buoyant pine
#

No need for a template here

carmine aspen
#

right now i have it on a time trigger on certain days

buoyant pine
#

Yeah you can have multiple triggers, conditions, and actions in an automation, but let's go to #automations-archived

carmine aspen
#

ok

quiet kite
#

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?

arctic sorrel
quiet kite
#

I cannot belive to this.

arctic sorrel
#

Why?

quiet kite
#

because configuration by UI isnt easy to move or copy or share

arctic sorrel
#

Given that the config is the address, it's not like sharing it is that useful

quiet kite
#

ok :/

#

so, how i can define actions? When switch on then change state light.led to on

arctic sorrel
#

In ESPHome, that'd be a thing to ask on their Discord

quiet kite
#

ok, thanks

brittle saddle
silent barnBOT
arctic sorrel
#

Test your template, make sure it works

brittle saddle
#

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

arctic sorrel
#

If only we had templating documentation...

#
          {% if is_state('binary_sensor.back_door','on') %} <li>Back Door is
          Open</li>{% endif %}
brittle saddle
#

oh i just copy paste what mono gave me so i just assumed it was correct

ivory delta
#

I can't template, don't trust me 😄

brittle saddle
#

lol ok i will keep it in mind! 🙂

arctic sorrel
#

Trust but verify

brittle saddle
#

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

arctic sorrel
#

Which would be correct

brittle saddle
#

i thought it would print all the available states

arctic sorrel
#

No

brittle saddle
#

how would i go about finding the possible states of an entity? i know its not needed in this case

arctic sorrel
#

Other than for things that are binary there's an infinite number of available states

brittle saddle
#

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

arctic sorrel
#

Well, yes

#

That's explained in the fine manual

#

And also easily seen by looking in devtools -> States

brittle saddle
#

oh very nice thanks

brittle saddle
#

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

ivory delta
#

They're both templating engines. They're all trying to do the same thing.

hollow bramble
#

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

wispy shale
#

Is there a way I can put a phone on vibrate in a template?

arctic sorrel
#

Well, if there's an integration that supports it, then yes

wispy shale
#

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

arctic sorrel
#

Templates are just ways of allowing your automations and scripts to be flexible

wispy shale
#

Maybe I should ask there then, thanks

arctic sorrel
#

With scissors?

#

The actual answer will depend on context... 😉 What data you're working with, what you're looking to extract, etc etc etc

arctic sorrel
#

Photo... of text 🤔

#

devtools -> States @naive plinth - find the entity and copy and paste the attributes. Remember to use code markup 😉

silent barnBOT
#

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

naive plinth
#

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

arctic sorrel
#

Please copy and paste so we can see

#

Or

silent barnBOT
#

Please use imgur or other image sharing web sites, and share the link here.

patent flame
#
- 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

arctic sorrel
#

Why not just use a group?

patent flame
#

This sensor I want to be "ON" if some of this sensors are "ON"

#

err... cause I never thought of that....

arctic sorrel
#

I'm lazy...

patent flame
#

I thought this was the best way to do it...

arctic sorrel
#

Well, if you want the changing icon it is

patent flame
#

I don't have that idea of you... 🙂

#

yes I want to have a badge with the icon changing

arctic sorrel
#

I'd also swap states.binary_sensor.dw_varanda_sala_contact.state for states('binary_sensor.dw_varanda_sala_contact') (etc)

patent flame
#

will do

arctic sorrel
#

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

patent flame
#

with the first option it got the same result...

arctic sorrel
#

Yup 😉

patent flame
#

let's try the 2nd

arctic sorrel
#

That first option simply returns the current state

#

Given that the state is on and not true or false...

patent flame
#
        {{ 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?

arctic sorrel
patent flame
#

yeah...

unique gyro
#

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 }}'
ivory delta
#

What's the problem?

unique gyro
#

Sorry for no code formating. 😅

ivory delta
#

You can format like this:

silent barnBOT
#

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

unique gyro
#

Unfortunately it does not appear in HA 0.112.4

ivory delta
#

Where did you add it? And did you run the config checker?

unique gyro
#

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.

hollow bramble
#

No errors in your log after restart?

unique gyro
#

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.

hollow bramble
#

Where are you looking for the sensor?

unique gyro
#

In the entities.

hollow bramble
#

look in dev tools > states

unique gyro
#

I did it but no luck 😦

ivory delta
#

Which config check did you do? You should always do the command line one.

silent barnBOT
#

Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.

unique gyro
#

UI.

#

Neat! Let me do this! 🙂

#

The config checker exited with no output. Is that normal?

hollow bramble
#

that means the config is okay

unique gyro
#

Oh okay sorry about that. 😅

ivory delta
#

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 devtools > Templates?

unique gyro
ivory delta
#

Just the template part, not the whole sensor config.

#

The bit in {{}} without quotes.

unique gyro
#

Oh sorry. Let me see.

#

Is that ok?

ivory delta
#

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.

unique gyro
#

Alright then! 🙂 Thank you so much for that speedy help! 🚤

slow vine
#

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.

silent barnBOT
cedar chasm
#

Thanks for your help!!!

silent barnBOT
#

@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.

lunar osprey
#

Hello

#

is there a way to read "states.sensor.salone_temperatura.last_updated" in javascript

cedar chasm
#

@rugged laurel My text is that long. Wasn't able to make it shorter to explain my problem

lunar osprey
#

on the lovelace UI?

ivory delta
cedar chasm
#

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

arctic sorrel
#

Why are you channel hopping?

cedar chasm
#

sorry, was wrong. deleted

sage fable
#

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?

arctic sorrel
#

Because, it doesn't have any entities so it doesn't update

sage fable
#

ah, so theres no way to just have it use all 'Persons'?

arctic sorrel
#

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

ivory delta
#

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)

sage fable
#

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

ivory delta
#

Which would be great if it was designed to work that way 🤷‍♂️

sage fable
#

it will work like that i think with with the time entity as per @arctic sorrel's suggestion

ivory delta
#

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.

sage fable
#

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 😑

hollow bramble
#

Realistically, how often are you adding a person to your system?

sage fable
#

Its because I add guests, so that automations trigger just the same way based on their presence

ivory delta
#

No guest mode? 😮

sage fable
#

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

hollow bramble
#

Adding guests as persons is... more work than I would be willing to do

ivory delta
#

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.

sage fable
#

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...

hollow bramble
#

Heh, wifi device trackers. Yikes

sage fable
#

Unifi has been solid for tracking based on wifi for me.

buoyant pine
#

Yeah I use unifi for some limited device tracking, seems to work well

arctic sorrel
#

Bluetooth tracking FTW 😛

buoyant pine
#

I'm too lazy to set up monitor

candid gate
#

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)

arctic sorrel
#

Template in an automation, yes

#

However...

silent barnBOT
#

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.

arctic sorrel
#

It might be that a light.group is what you're after, or a Zigbee group, or ...

candid gate
#

ah

#

indeed.

#

didn't think of that

silent barnBOT
candid gate
#

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

arctic sorrel
#

No, but ... you're explaining your solution, not your problem 😉

#

With a light group you can turn on/off the group

candid gate
#

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

arctic sorrel
#

You can do it with templates, to match the state of the trigger entity

silent barnBOT
candid gate
#

you said automation templates, but this gave me no useful result when I searched

arctic sorrel
#

Automations are how things happen in HA - how it reacts

#

Templates are how you make those flexible

candid gate
#

and I don't see how this makes it any easier to my current solution of having two rules

arctic sorrel
#

One, more complicated one

#

Easier... not necessarily, but you said you wanted to do it without two

candid gate
#

I had hoped it was something obvious I had missed

#

smartthings has a mode doing just that, to emulate a 2-way light switch

arctic sorrel
#

HA doesn't natively do that

#

On the other hand, the automation and templating engine is powerful enough you can do it yourself

ivory delta
#

My only warning with using automations to do this would be: consider the timings.

candid gate
#

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

ivory delta
#

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.

arctic sorrel
#

I personally keep all my manual automations out of automations.yaml, but you can mix them in there if you want to

candid gate
#

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?

candid gate
#

do you do something similar to the script: and input_text: entries?

arctic sorrel
#

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

candid gate
#

those files are to be saved in the same folder?

arctic sorrel
#

For which?

#

The script editor edits scripts.yaml

candid gate
#

any of those

arctic sorrel
#

"Helpers" go directly to storage, and aren't in YAML

candid gate
#

ok cool

#

@arctic sorrel cool floorplan !

#

mine suck in comparison 🙂

arctic sorrel
#

It took... some time to get right

candid gate
#

i can imagine

ivory delta
#

You said 30 minutes 😮

arctic sorrel
#

30 minutes... at a time 😄

candid gate
#

i draw something with a tool going over some old floorplan I had on paper

#

looks shit really 🙂

arctic sorrel
#

I used Inkscape and layers

#

All the base shapes are rectangles, lined up very carefully at maximum zoom

hollow bramble
candid gate
#

@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?

arctic sorrel
#

I don't, only one I've got is for joining

candid gate
#

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

arctic sorrel
#

It's all the same, just in pieces

candid gate
#

well, not quite, it doesn't have the same indentation nor automations.

#

hmm, keep getting errors about expecting keys

arctic sorrel
#

Well, indentation changes because it's included at that level

#

So, each included file starts at zero

amber night
#

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?

silent barnBOT
mighty ledge
#

It’s required so it knows what to call based on the current state for toggle

arctic sorrel
#

Show us the whole switch definition please 😉

silent barnBOT
amber night
#

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

silent barnBOT
#

@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.

arctic sorrel
#

You need whatever logic works for you 😉

#

If the switch is on when both are on, then yes

hollow bramble
#

&& doesn't work. and

buoyant pine
#

this ain't bash

hollow bramble
#

Or <insert 99% of programming languages here>

amber night
#

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

mighty ledge
#

@amber night the language is Jinja2

#

it's almost identical to python but it has these things called filters

amber night
#

I guess I could do "or" in case the power is out on one of the thermostats and the switch would still work?

silent barnBOT
dreamy sinew
#

Jinja has a lot of similarities to python in syntax

amber night
#

OIC thank you

hollow bramble
#

in some cases you use python syntax directly

mighty ledge
#

Well, that's just home assistants version of it. Jinja itself does not have those python calls.

amber night
#

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

mighty ledge
#

good news then, you don't have to manage memory

amber night
#

🙂

naive plinth
#

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

ivory delta
#

That whole string is the state? Where does it come from?

chrome temple
#

@naive plinth {{ states('sensor.ups')|regex_findall_index('Bus Voltage: ([0-9.]+) V') }}

naive plinth
#

Thx

silent barnBOT
#

@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.

arctic sorrel
#

And no, that won't update, for all the reasons warned in the templating docs 😉

dull bloom
#

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

arctic sorrel
#

Your template updates when input_boolean.leia_pooped updates

#

But, you do realise most cards can display that information without this 😉

dull bloom
#

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

arctic sorrel
#

You can do it in a template, but exclude it from history/recorder if you do that

dull bloom
#

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

arctic sorrel
dull bloom
#

ugh... so much to learn

arctic sorrel
#

The price of great power flexibility 😉

dull bloom
#

I'm taking a break... been at this all day... eyes are crossing

calm tinsel
#

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') }}"

arctic sorrel
#

It's basically just high school maths, with a tiny twist that templates produce strings, so you need to turn them into numbers again

calm tinsel
#

@arctic sorrel I understand its basic maths, just can't get the syntax right.
Thanks will try the examples thanks.

arctic sorrel
#

Well, if you get stuck, show us what you've tried 😉

mighty ledge
#

@calm tinsel value_template: "{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | float / 100 }}"

arctic sorrel
#

Pffft, I was trying to teach him to fish...

mighty ledge
#

🤣

#

| float is foreign to everyone who doesn't code

#

tbh we kinda handle it poorly in HA

arctic sorrel
#

Yeah, stuff like that it should just convert it anyway

mighty ledge
#

It might actually be a float because it's an attribute

#

but, that depends on the integration

arctic sorrel
#

You probably want to round it off too

mighty ledge
#

maybe some day we will have a system in place for strongly typing crap

arctic sorrel
#

I'd like a system that just goes oh, you want to treat that like a number, sure

calm tinsel
#

@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 🙂

arctic sorrel
#

It won't take long to get the basics

calm tinsel
#

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

ivory delta
#

Order of operations, methinks.

arctic sorrel
#

What does

{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | float }}
``` show?
calm tinsel
#

0.0

arctic sorrel
#

I suspect the attribute has the quotes as part of the value

#

Saw this with somebody the other day

calm tinsel
#

yes it does

#

battery: 100
trigTime: "1595014489061"
temperature: "1537"
humidity: "3091"

arctic sorrel
#

That's... stupid on part of the integration

#

Faced this the other day 😉

daring musk
#

use replace(""", "")

#

to remove quotes

chrome temple
#

|replace('"', '')

arctic sorrel
#

Not replace('"', '')?

daring musk
#

{{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | replace('"','') }}

#

yeah

calm tinsel
#

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('"','') }}

daring musk
#

value_template: >- {{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | replace('"','') }}

#

try this

calm tinsel
#

No luck

#

@daring musk getting late here.. I will try again in the morning.
Cheers to all that helped.

chrome temple
#

@calm tinsel

value_template: >
  {{ state_attr('binary_sensor.sonoff_a400006115', 'temperature') | replace('"','') }}
amber night
#

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?

amber night
#

I think what I'm looking for is input_boolean ok, ok makin progress

buoyant pine
#

@amber night what is the template switch for?

amber night
#

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!

calm tinsel
#

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?

ivory delta
#

I'm fairly sure the pipe doesn't go inside the call to state_attr.

buoyant pine
#

Keep the first but add a ) after 'temperature'

#

And then remove the extra closing parenthesis

calm tinsel
#

@ivory delta thank you

buoyant pine
#

Also for future reference @calm tinsel :

silent barnBOT
#

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

misty pasture
#

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 }}

dreamy sinew
#

It might not update though

candid iron
#
  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 ```
chrome temple
#

Indent volume_level.

#

And get rid of {} after data_template:.

candid iron
#

im trying to get this working but keep getting an error @plucky token volume level

#

okay will try

chrome temple
#
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 
candid iron
#

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']

chrome temple
#

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. 😉

candid iron
#

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

chrome temple
#

@candid iron Why don't you just use the media_player.volume_up service?

candid iron
#

let me try

chrome temple
#

I think it just accepts an entity_id parameter, and increments the volume by 0.1, up to, but not exceeding, 1.0.

candid iron
#

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

dreamy sinew
#

Rule 1 of templating

silent barnBOT
candid iron
#

do you need to create a template yaml file to reference a template or does home assistant just recognise the syntax ?

buoyant dirge
#

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

dreamy sinew
#

Sorry, got trigger happy

buoyant dirge
#

if change the same sensor name, or have to create a new one or how it works

dreamy sinew
#

Some integrations support templates in their configuration. The docs for that integration will indicate if they do

buoyant dirge
#

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

buoyant dirge
#

is somebody here?

silent barnBOT
#

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:

  1. What version of the Home Assistant are you running? (remember, last isn't a version)
  2. What exactly are you trying to do that won't work?
  3. Is the problem uniform or erratic?
  4. What's the exact error message?
  5. When did it arise?
  6. What exactly don't you "get"?
  7. Can you share sample code, ideally with line errors where the error occurs?
buoyant dirge
#

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????

silent barnBOT
arctic sorrel
#

Does it work when you test it?

#

The value shouldn't have C in it, since it's already covered by unit_of_measurement

buoyant dirge
#

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

arctic sorrel
#

Ah... your system is using Imperial units...

buoyant dirge
#

yes

arctic sorrel
#

HA will auto convert 😉

#

So, the template works, exactly as expected

buoyant dirge
#
    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

arctic sorrel
#

No, the top one shows you a string

#

The bottom one shows you a number

buoyant dirge
#

ok, So, What should I do to make it work?

arctic sorrel
#

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

buoyant dirge
#

I want shows in C, because the 3d printer is the values always use

arctic sorrel
#

Then you need the first, the string

buoyant dirge
#

I want use a number, but in C

arctic sorrel
#

then convert your whole system to C

#

These are your choices

#

There is no magic third option

buoyant dirge
#

but, everything else in US is F, just the printer

#

is C

arctic sorrel
#

🤷

buoyant dirge
#

hoo, I thugh HA can do a conversion just with unit of measurement

warm isle
#

@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 }}
ripe snow
#

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"

sonic nimbus
#

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

ripe snow
#

you can use a condition before the service @sonic nimbus

ivory delta
#

You don't put if statements in scripts. Scripts are a linear sequence of actions.

#

If a condition fails, it won't continue.

sonic nimbus
#

@ripe snow I want two services to trigger above

#

but third is conditioned only

ivory delta
sonic nimbus
#

if I put condition to whole script, first two services wont trigger

ivory delta
sonic nimbus
#

Yes I know, then I need to put in automation..

#

as I expected

ripe snow
#

You could put a condition before the last service call so that if the condition is not met the script doesn't continue

ivory delta
#
- service.one
- service.two
- condition
- service.three```
sonic nimbus
#

really? 🙂 I didnt know that! thanks!

ivory delta
#

It's documented. Read the page I shared.

#

In fact, read all the things.

rugged laurel
#

You are correct @ripe snow that should be a template sensor where you specify a entity_id that regularry updates

ripe snow
#

Thanks @rugged laurel!
LTNS ahaha

rugged laurel
#

Yeah, it's been a while since I saw you on these parts

ripe snow
#

Been very busy with life in general, I don't wanna go off-topic, tho @rugged laurel

placid stirrup
#

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.

silent barnBOT
arctic sorrel
#

Show us the sensor, using a code share site 😉

#

(Yes, you can, but... probably the template is "wrong")

placid stirrup
arctic sorrel
#

Well, the indenting is a train wreck, but it should auto update when any of those entities update

placid stirrup
#

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

arctic sorrel
#

homeassistant.update_entity

placid stirrup
#

Yes i already tried that.. but it doesn't update, tried it on the template sensor as well on the temp sensors

arctic sorrel
#

Well, if the value doesn't change, the state won't change

placid stirrup
#

That's correct, but when you use force_update for example on a REST sensor, it does actually.

arctic sorrel
#

That's likely because other things change too, attributes etc

ivory delta
#

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.

placid stirrup
#

Yes, that's exactly what i want to achieve..

ivory delta
#

Cool... but that's not the same thing as the state changing.

ripe snow
placid stirrup
#

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?

arctic sorrel
#

If the attributes change, maybe

chrome temple
#

@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! 😉 )

tidal heart
#

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

arctic sorrel
#

In the frontend you can show that in many cards, without writing a template

tidal heart
#

@arctic sorrel Isn't that only as secondary text?

arctic sorrel
#

Yes

tidal heart
#

I would like it to be the main

daring musk
#

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
{{ relative_time(states. binary_sensor.last_alarm_triggered.last_updated) }}

humble beacon
#

Hi. Is it right, that time templates always gives me english values?

daring musk
#

relative_time template filter does give only english

#

codebase of template language is not part of hass if i understand correctly

ivory delta
#

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.

ivory delta
#

@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.

plush harbor
#

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'

ivory delta
#

Ahh... one sec

plush harbor
#

is there some sort of hex decoding issue?

ivory delta
#

Not hex. Numbers in general.

plush harbor
#

yes, that solve it

#

ah, riiiiiiiight at the bottom of the documentation. my bad. Thanks @ivory delta

ivory delta
#

You're welcome

little gale
#

How do I set the on switch for a template when a device tracker reports not_home or home?

ivory delta
#

An 'on switch'? What are you trying to do?

little gale
#

template switch value template

ivory delta
#

I don't want to know your solution. What are you trying to do?

little gale
#

Trying to set the state of a switch if the device is connected

ivory delta
#

Why? What are you trying to do? You're still describing a solution.

little gale
#

Shutting down a computer basically

ivory delta
#

Why does that mean you need a switch?

little gale
#

Toggling the switch issues a cURL request that shuts down the computer

ivory delta
#

No. Turning the switch off might. Toggling goes both ways. What do you do when you turn it on?

little gale
#

It wont go through

#

I managed to figure it out. thanks for your time

ivory delta
#

🤦‍♂️

mighty ledge
#
switch:
- platform: template
  switches:
    pc:
      value_template: "{{ is_state('device_tracker.xxx', 'home') }}"
      turn_on:
        service: ... curl on
      turn_off:
        service: ... curl off
little gale
#

yep, I had set it to states instead lol

mighty ledge
#

that'll get you a switch that turns on/off your pc.

#

@ivory delta take a chill pill. Not everyone is stupid.

ivory delta
#

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.

mighty ledge
#

Yes, but you aren't being nice.

little gale
#

I appreciate all of y'all in the forums and dont want to cause any unnecessary discord.

ivory delta
#

There's... no discord here.

little gale
#

well

#

wol is kinda useless to me cuz the laptop usually is awake or shut down (doesnt have a battery so...)

ivory delta
#

That makes sense. I didn't know it was a laptop.

orchid onyx
#

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? 🙂

buoyant pine
#

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

orchid onyx
#

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

buoyant pine
#

probably doesn't like the period at the end of the value_template

orchid onyx
#

What does that mean? 😫

buoyant pine
#
or not is_state('sensor.hallway_nest_protect_battery_health', "Ok"). }}
#

remove the period at the end

orchid onyx
#

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!!! 😍

orchid onyx
#

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? 😦

buoyant pine
#

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

orchid onyx
#

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' }}

buoyant pine
#

what's the state of the binary sensor you created when all sensors are Ok?

orchid onyx
#

In states it says: On

#

Ok, so thats why its "triggered" but why is the state "On" if all states on sensors are "Ok"?

buoyant pine
#

are the entity IDs in the template correct?

hollow bramble
#

What does the template render as in the templates dev tool?

#

Try them one at a time

orchid onyx
#

Ok, akward... it was the entity ID's that was wrong

hollow bramble
#

It happens

orchid onyx
#

Thanks again.

orchid onyx
#

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 ? 😦

buoyant pine
#

do you have binary_sensor: at the top of binary_sensor.yaml?

#

if so, remove it

orchid onyx
#

yes, i tryed also to remove that one but i cant compile the file then.. but somewhere there is the problem?

buoyant pine
#

what do you mean by "i cant compile the file then"?

orchid onyx
#

First part of "binary_sensor.yaml"

binary_sensor: - platform: template sensors: # Contact Sensor alarm_ytterdorr:

buoyant pine
#

right, remove binary_sensor: from the top

orchid onyx
#

I mean, I cant save the file without getting error. My HA is in swedish 😒

#

Sec i will try it

charred dagger
#

You mean vscode complains about the syntax?

#

It'd probably do that.

orchid onyx
#

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

silent barnBOT
chrome temple
#
  - platform: template
    sensors:
      climate_hall:
        friendly_name: 'Luftfuktighet'
        ...
orchid onyx
#

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!

chrome temple
#

tabs?

#

Yeah, don't use tab characters in YAML files. YAML doesn't like them much.

brisk temple
#

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

inner mesa
#

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

brisk temple
#

I tested by doing a set, but it's not true test

inner mesa
#

What do you mean by ‘not working’? trigger.from_state.state is ‘unknown’ in the action:?

brisk temple
#

it's a condition in the trigger

inner mesa
#

Share the whole thing?

#

Conditions and triggers are different things, so I’m confused

brisk temple
#

I removed the .state but hard to test because it only happens on reboot

inner mesa
#

Thanks, that’s not trivial

brisk temple
#

And not everytime

inner mesa
#

Read the docs that I posted above

#

That’s not your problem

#

What is your evidence that it’s not working?

brisk temple
#

It's going from unknown to the version and alerting me

inner mesa
#

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

brisk temple
#

I put them both in because I wasn't sure the state it was coming from, I didn't want to sit and constantly restart HA

#

Since it doesn't always happen, but it was unknown an HR ago

inner mesa
#

sure, I understand. but think about the logic a bit more

#

I think you want an "or" between the first 2 and the last two and the two results anded together

#

I often find it easier to just write the whole template than to try to and do something complicated like that in YAML