#templates-archived

1 messages ยท Page 94 of 1

gusty nimbus
#

but i think alot changed in 2 years because it didn't worked ๐Ÿ™‚

buoyant pine
#

Sorry, I misread something you said above. If the sensor has a value like 70 F | 40% you won't be able to see a graph with temp and humidity if that's what you're asking

gusty nimbus
#

oh ok

#

thats why people don't put them in the same line and make a card for temp & card for hum some times i think ๐Ÿ˜‰

fast mason
#

Anyone knows why isn't rendering?
{{ trigger.event.data.entity_id.endswith('sensor.17track_package_')}}
It's giving me UndefinedError: 'trigger' is undefined

hollow bramble
#

Is this in an automation?

merry fable
#

@mighty ledge Thank you โค๏ธ I hadn't attached a date. You fixed my problem.

olive moth
#

@buoyant pine for the moment it switches between off an cool all the time... maybe because of the delay between the both. 1 turns cool but 2 is still off which troggers 1 to turn off again and vise versa. but your condition might be a good idea.. how would that conditon look like?

#

you mean like this for the multiple entites in trigger and automation:?

silent barnBOT
arctic sorrel
#

~rule6 @olive moth

silent barnBOT
#

@olive moth Rule #6: Spam will not be tolerated, including but not limited to: self-promotion, flooding, codewalls (longer than 15 lines) and unapproved bots.

Please take the time now to review all of the rules and references in #rules.

fast mason
#

@hollow bramble it's supposed to be but it was erroring out in the logs with that error. So then was trying to test the individual conditions on the template tab and all give me the same error.

#

I got the automation from a thread in the community forum and from searching I've seen others use that type of template before but I don't understand the problem. And couldn't fine any breaking changes in case something had changes a while back

mighty ledge
#

@fast mason testing it in the template tab wont work because you don't have a trigger object. It will only work in automation conditions or actions. Also, your testing the entity_id string with 'endswith' but the string appears to be the start of the entity_id. I would assume you want .startswith( instead.

silent barnBOT
fast mason
#

oops was too big I guess.. It moved my text with it though ๐Ÿ˜‚

#

at first I was assuming my trigger was the isssue rather than the templates but not sure

thorny snow
arctic sorrel
#
โ€œ
#

That's your problem - "smart" quotes

#

Fix all of those, then run a config check

silent barnBOT
#

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

thorny snow
#

single quotes then?

arctic sorrel
#

Nope, that's not it

#
" โ€œ
#

Look closely ๐Ÿ˜‰

thorny snow
#

I'm sorry, not familiar with smart quotes.

arctic sorrel
#

You used a word processor, not a text editor

#

You got "smart" quotes, for humans

thorny snow
#

HA! Well, in all fairness I cntrl-v/cntrl-c from the community... So, no clue how he got it to work... but thanks for the headsup, I wasn't even aware there was a difference.

lunar osprey
#

Hello

silent barnBOT
lunar osprey
#

This is working

silent barnBOT
lunar osprey
#
                            tap_action:
                              action: call-service
                              service: vacuum.send_command
                              service_data:
                                command: clean
                                entity_id: vacuum.aspirapolvere
                                params:
                                  act: 'start'
                                  content: '2'
                                  count: 2
                                  type: 'spotArea'                                
                            type: state-icon
#

but in this way... it's not working

#
vacuum_clean_zone:
  alias: Pulisci zona
  sequence:
  - service: vacuum.send_command
    data_template:
      command: clean 
      entity_id: vacuum.aspirapolvere 
      params:
        act: 'start'
        type: 'spotArea'
        count: >-
              {%- if is_state('input_boolean.deebot_times', 'on') -%}{{2|int}}{%- else
              -%}{{1|int}}{% endif %}
        content: >-
              {{-states('input_text.idstanze')[:-1]}}
#

I got 'count': '2'

#

instead of 'count': 2

#

without apex

#

how can I set the template to send an integer

#

instead of a text?

arctic sorrel
#

~rule6 @lunar osprey

silent barnBOT
#

@lunar osprey Rule #6: Spam will not be tolerated, including but not limited to: self-promotion, flooding, codewalls (longer than 15 lines) and unapproved bots.

Please take the time now to review all of the rules and references in #rules.

arctic sorrel
#

Try

              {{ "2" if is_state('input_boolean.deebot_times', 'on') else "1" }}
inner mesa
#

@thorny snow That guy posted unformatted code in the forum, so all bets are off.

fiery ravine
#

Is there a quick way to grab the "condition" i.e. cloud, wet, sunny from the forecast from the weather sensor? I'd like to get tomorrows data from the forecast but I'm having trouble accessing attributes inside {{ state_attr('weather.the_retreat','forecast') }}. This is using NMI the default Home Assistant weather provider.

arctic sorrel
#

Probably that's an array

#

Try the following in devtools -> Templates

{{ states.weather.the_retreat.attributes.forecast }}
lunar osprey
#

it doesn't work...

#

count: >
{{ "2" if is_state('input_boolean.deebot_times', 'on') else "1" }}

#

I get: {'act': 'start', 'type': 'spotArea', 'count': '2', 'content': '2'}

#

I should get instead: {'act': 'start', 'type': 'spotArea', 'count': 2, 'content': '2'}

arctic sorrel
#

Unfortunately the integration really needs to handle getting a number in quotes. I'd open an issue against it

lunar osprey
#

shall I open a bug to vacuum component then?

arctic sorrel
#

That's what I just said ๐Ÿ˜‰

lunar osprey
#

ok

fiery ravine
#

Try the following in devtools -> Templates

{{ states.weather.the_retreat.attributes.forecast }}

Thanks @arctic sorrel. I tried similar but I was using the {{ states('') }} method. Using your suggestion I can dial in perfectly. Thank you. {{ states.weather.the_retreat.attributes.forecast[0].condition }}.

fiery ravine
arctic sorrel
#

@fiery ravine And you tagged me in that because ... ?

fiery ravine
#

My apologies, just closing the loop.

thorny snow
#

hi all! I require some assistance with getting a reading out from command line sensor. When I manually type to commandline for example cat /dev/ttyUSB0 it gives me correct string. Hexdump returns me the actual hex values I want. But when I try to setup a command line sensor to get the reading to show up in UI I get unknown always... what am I doing wrong?

arctic sorrel
#

How did you install HA?

thorny snow
#

I am using latest HassOS on Rasp4. I installed according to latest instructions from official website

arctic sorrel
#

You'll want to check that your USB device is passed through - #330990055533576204 can help there

thorny snow
#

Thanks I'll ask them

normal badger
#

Hello one question: I have created an input bolean for my letter box telling me if it is full or after I fetched the mail empty.
In fact, it tells me on or off. Is it possible to change the possible states to full or empty instead of on or off, or is it possible to at least display it differently in Lovelace? Thanks for your help

arctic sorrel
#

With a template sensor, sure

#
value_template: "{{ 'Full' if is_state('input_boolean.mailbox','on') else 'Empty' }}"
normal badger
#

Ok nice thanks very much for that approach, will give it a shot

thorny snow
#

Hello, can i have one question, i try to setup an automation for my vacuum that allows me to choose multiple rooms for segemented cleaning (aka room cleaning). Entities are input_booleans that manually assigned room_id parameter in customize.yaml. At the end this is what gives a parameter value in a data_template{{ roomIds.split(',')|map('int')|list }} This template returns a list of integers and my service call gives this error Unable to send command to the vacuum: {'code': -10005, 'message': 'data for segment is not a number'} but in other automation this is how i pass this variable manually and this just works fine
`

  • service: vacuum.send_command
    data:
    entity_id: vacuum.xiaomi_vacuum_cleaner
    command: app_segment_clean
    params: [19,20,23]
    `

Anyone have a solution for this maybe?

worn apex
#

Hi, mates!

#

Is there any way to test in a wait_template, a sensor for being less than X, for longer than Y seconds?

#

example:

  {{ states('sensor.shp7_cozinha_potencia') | int < 300 for 00:00:30 }}```
arctic sorrel
#
{{ (states('sensor.shp7_cozinha_potencia') | int < 300) and ((now() - states.sensor.shp7_cozinha_potencia.last_updated).seconds > 30) }}
``` probably
worn apex
#

I think the second part of that statement will be always false as the sensor updates every second with a new value, regardless which is. :/

arctic sorrel
#

Then you need to create a template binary sensor that's on when it's below 300 and off above, and use the state of that

worn apex
#

Thanks!

thorny snow
#

Can anyone take a look at these templates from my config? The first two are working, but the bottom three are not and I can't spot the difference. (I literally copy and pasted and changed a '_type_2' to a '_type_3'
https://paste.ubuntu.com/p/RQRNnkYsFf/

ivory delta
#

I'd suggest checking the states to see if they do what you think they do. devtools > States, and find those entities.

silent barnBOT
buoyant pine
#

You can also put all of those sensors under one - platform: template

wise citrus
#

{{ state.attributes.Days-until }} with what do you need to replace the '-' with? can't find in documentation maybe i am blind

arctic sorrel
#

Is the attribute Days-until?

wise citrus
#

yes

arctic sorrel
#

That's... unfortunate

rugged laurel
#

"{{ state.attributes['Days-until'] }}"

arctic sorrel
#

Maybe {{ state.attributes[Days-until] }}?

#

There we go, somebody who groks more than me

dreamy sinew
#

yeah, needs to be in quotes

#

or state.attributes.get('Days-until')

rugged laurel
#

if not in quotes it tries to substract untill from Days

#

and look for the result of that substracion (which will fail) as a key in the attrributes

wise citrus
#

Value cannot be processed as a number that is really weird

dreamy sinew
#

did you do it with no quotes?

#

because that's what Ludeeus is talking about

wise citrus
#

yes with the quotes

dreamy sinew
#

are you using the template tester?

rugged laurel
#

Sounds like we are missing some part of the information here, or rule 1 of templating was not folowed ๐Ÿคทโ€โ™‚๏ธ

silent barnBOT
rugged laurel
#

the entire thing

wise citrus
#

i changed already the quote thing

rugged laurel
#

IC

dreamy sinew
#

that paste doesn't have any of the changes we suggested

rugged laurel
#

"{{ state_attr('sensor.mijnafvalwijzer_restafval', 'Days-until') | int }}"

wise citrus
#

same problem sadly

dreamy sinew
#

test that in the template tester

wise citrus
#

yeah that works

#

but that is python right the trigger is in yaml so other rules?

rugged laurel
#

Then you did not paste it the same way

hollow bramble
#

yaml is not a programming language, and templates are not python

wise citrus
#

ah i got it to work

#

used my own text editor instead trough ui

#

until yesterday i had never did do any yaml or python

hollow bramble
#

And you still haven't done any python ๐Ÿ™‚

wise citrus
#

what did i copy paste then?

hollow bramble
#

a jinja template

dreamy sinew
#

yaml that contains a jinja2 template

wise citrus
#

well somehow it looks a little bit like razor

misty pasture
#

is there a mechanism with which I can convert data provided to my service into a JSON payload for a rest_command I'm building?

narrow ginkgo
#

@misty pasture you can print objects passed as a JSON. for example your service data could be:

{"payload": {"foo": "bar", "xyz": 123}}

Then you just need to use {{ payload | tojson }} as your payload

cyan solar
#

Hello, I'm not sure if i'm here right. But my question is: I have setup glances on several systems. I can get the uptime of the servers as strings in the format: "73 days, 22:52:39". Is there any chance to get it displayed as "73d 22h 52m"

coarse tiger
#

so I want to have multiple device_tracker entities displayed as on/off instead of home/not_home
Is there a generic template way to make this happen or do I need to create templates for each of them? (20-30 entities)

arctic sorrel
#

Template for each one

coarse tiger
#

@arctic sorrel can you please stop always being so correct, I don't like to do hard work ๐Ÿ˜„

#

oh well someday one will be able to just do cosmetic things like this via the frontend I hope

misty pasture
#

How should I modify this to make it evaluate the same as color: "blue"?

name: Send One Blue
tap_action:
  action: call-service
  service: my_service
  service_data:
    payload:
      color: >
        [[[
          return "blue";
        ]]]
      count: 1
type: button
clever fable
#

Can someone help me with this binary_sensor?

#
    sensors:
      living_room_occupied:
        value_template: >-
          {{ is_state('binary_sensor.front_door', 'on')
             or is_state('binary_sensor.living_room_1_motion', 'on')
             or is state('binary_sensor.living_room_2_motion', 'on') }}```
#

I'm sure I'm way off but I cant find any examples online

buoyant pine
#

what problem are you having?

#

it looks fine, at least as far as syntax

clever fable
#

I dont know its not passing the check

buoyant pine
#

what's the error

inner mesa
#

You need an if

buoyant pine
#

also test the template at developer tools > template

inner mesa
#

Whatever

buoyant pine
#

you don't need an if, you can do a statement like that

clever fable
#

Invalid config for [binary_sensor.template]: invalid template (TemplateSyntaxError: expected token 'end of print statement', got 'state') for dictionary value @ data['sensors']['living_room_occupied']['value_template']. Got "{{ is_state('binary_sensor.front_door', 'on')\n or is_state('binary_sensor.living_room_1_motion', 'on')\n or is state('binary_sensor.living_room_2_motion', 'on') }}". (See ?, line ?).

buoyant pine
#

oh it doesn't like the newlines

clever fable
#

Ahhh should it have just been a comma

buoyant pine
#

try it all on one line

clever fable
#

Ok

buoyant pine
#

oh wait

#

nope. is state on the last line

#

needs to be is_state

#

didn't even see that until now lol

clever fable
#

Ah

#

That was it. Thanks @buoyant pine

buoyant pine
#

@inner mesa this is an example of a template i use in a template binary sensor:

"{{ is_state('sensor.xbox_status', 'Available') }}"

the template just needs to result in True or False, you don't need to specifically use an if/else statement

brisk temple
#

is using as_timestamp(now()) in a template an issue?

#

some reason i feel like i've read not to do that

#

n/m it's in the examples so I am going to go for it

worn nova
#

Trying to get an icon to change based on the state of a template sensor, can the sensor point to itself for the icon change?

    sensors:
      sprinkler_ban:
        friendly_name: "Sprinkler Ban"
        value_template: >-
          {{ now().month >= 6 and now().month < 9 }}
        icon_template: >-
          {% if is_state("sensor.sprinkler_ban","true")  %}
            mdi:water-off
          {% else %}
            mdi:water
          {% endif %}
ivory delta
#

Recursion is generally a bad idea unless you know what you're doing.

#

Also, why not just use the expression you've already worked out (now().month >= 6 and now().month < 9) in both parts?

worn nova
#

Ok thanks, will give that a go, honestly didn't even think of it.

dreamy sinew
#

6 <= now().month < 9

fierce hornet
#

Would someone happen to know why this is happening? I've made a date sensor but for some reason it sometimes doesn't update. Here it went from 3-6 to 7-6 because I restarted HA: http://werra11.eu/i/07-06-2020_19:30:05.png. Using following config:

- platform: template
    sensors:
      dagmaand:
        friendly_name: Datum
        value_template: >         
          {{ now().day }} - {{ now().month }}```
inner mesa
fierce hornet
#

Ah I see now, thank you!

blazing wagon
#

Can someone please write me a template that checks if a sensor is greater than 0?

arctic sorrel
#
{{ states('sensor.brains')|int > 0 }}
blazing wagon
#

Thanks

buoyant pine
#

Long time no see, clippy

blazing wagon
#

Heh

raw dust
#

Hi all, how can I use a template inside a template? The 'myattribute{{ i }}' part is not working:

{% for i in range(11) %}
 {{ state_attr('sensor.mysensor', 'myattribute{{ i }}') }}
{% endfor %}
charred dagger
#

Do you want it to be e.g. 'myattribute1', 'myattribute2' etc?

raw dust
#

yes

charred dagger
#

What you want is called "string concatenation".

#

{{ state_attr('sensor.mysensor', 'myattribute' + ( i | string ) ) }}

#

You need the | string because you can't add an integer to a piece of text, but if you turn it into text first, then the program will know what you meant.

raw dust
#

Oh, I see, thank you. I was trying to concatenate {{ i }} instead of ( i | string )

stone lintel
#

I'm using ha dockermon and trying to get CPU stats for my docker containers. I use this for the memory stats but was hoping someone could help with CPU?

 - platform: rest
   resource: 
http://192.168.68.110:7777/container/ha_dockermon/stats
   name: HA Dockermon Memory
   scan_interval: 900
   value_template: '{{ (value_json.memory_stats.usage /1024/1024) |round(2) }}'
   unit_of_measurement: 'MB'
 - platform: average
   name: ha_dockermon_memory_average
   entities:
     - sensor.ha_dockermon_memory
   duration:
     days: 2
velvet gate
#

can I use a template in json in a service node? I tried this and it doesn't work.

{
    "entity_id": [
        "light.dining_room"
    ],
    "brightness": "{{states('sensor.rotary_encoder')}}",
    "xy_color": [
        0.37,
        0.372
    ]
}
narrow ginkgo
#

@velvet gate if the service itself does not support templates, you should use data_template instead of data

velvet gate
#

well I'm using a service node in node-red and doing light.turn_on

buoyant pine
velvet gate
#

rah

tawny coral
#

i believe it's line 4-5 that's giving me issues

arctic sorrel
#
      value_template: "{{ states('sensor.current' > 0 }}"
                                                 ^
``` ![shockscream](https://cdn.discordapp.com/emojis/707237581154418709.webp?size=128 "shockscream")
silent barnBOT
tawny coral
#

thank you! will have a look

arctic sorrel
#

) will certainly help

tawny coral
#

so that page leads me to believe that i should use numeric state trigger

#

but i don't understand the valuetemplate part of the instruction

#

value_template: "{{ state.attributes.battery }}"

#

where do i deduce what i should be using? state.attributes.current?

#

alias: 'Turn off charging if electricity is expensive and car is charging'
trigger:
- platform: numeric_state
entity_id: sensor.current
value_template: "{{ states('sensor.current' }}"
above: 0

#

it's questionable if it's even necessary

arctic sorrel
#

That value template returns the state of the entity, it's pointless

#

If sensor.current has the value you need for the state, that's all you need

tawny coral
#

then this should be fine:
- platform: numeric_state
entity_id: sensor.current
above: 0

arctic sorrel
#

Sure

tawny coral
#

now the only issue is my delay

#

i mean how can i be getting this wrong

#
  • id: '12'
    alias: 'Turn off charging if electricity is expensive and car is charging'
    trigger:
    • platform: numeric_state
      entity_id: sensor.current
      above: 0
      condition:
    • condition: template
      value_template: '{{ is_state("sensor.tibber_price_level", "EXPENSIVE") or is_state("sensor.tibber_price_level", "VERY_EXPENSIVE") }}'
      action:
    • service: switch.turn_off
      entity_id: switch.innr_plug
    • delay:
      minutes: 2
#

that's the full automation, the delay section still gives errors but it doesn't make sense. I've seen atleast 4 examples using it the same way

#

tried it with - delay: "00:02:00" as well

#

Invalid config for [automation]: [minutes] is an invalid option for [automation]. Check: automation->trigger->0->minutes. (See /config/configuration.yaml, line 12).

arctic sorrel
#

~share @tawny coral

silent barnBOT
arctic sorrel
#

That error has nothing to do with that automation

tawny coral
#

really? because if i remove the delay it doesn't give an error

#

aha i got 2 minutse errors

arctic sorrel
#

I'm not sure why you'd have a delay as the final action though ๐Ÿคท

#

If you can correctly format your code, it'll be easier to see what's a formatting error and what's not ๐Ÿ˜‰

tawny coral
#

aha i didn't know it mattered where in the action it was. obviously it should wait 2min and then turn off

arctic sorrel
#

Obviously the order matters...

#

a sequence of actions that Home Assistant will execute

#

Otherwise, how would things like delays and wait templates work?

tawny coral
#

in my would the delay would be assigned to the service or whatnot, be nested inside of it but yeah. I'm silly ๐Ÿ™‚

stone lintel
#

I'm trying to get a value template from the following
"cpu_stats":{"cpu_usage":{"total_usage":323907770833
I have this so far but keep getting an error value_template: '{{ (value_json.cpu_stats.total_usage }}'
Can someone point me in the right direction please?

tawny coral
#

so i just changed it to time_pattern instead of time and voila ๐Ÿ™‚

stone lintel
#

Is there a way to get this number 323907770833 which is CPU usage into a more user friendly number? I'm using a value template but not sure what to add to it?
'{{ (value_json.cpu_stats.cpu_usage.total_usage) |round(2) }}' the number it outputs as a sensor at the moment is 326742444571.0 %

mighty ledge
#

that doesn't look like cpu usage.

arctic sorrel
#

If that's a percentage, that's got a lot of CPUs

mortal ibex
#

Hey

#

Deploying latest ova in vcenter

#

Issues detected with selected template. Details: - 23:5:PARSE_ERROR: Parse error: Undeclared namespace prefix "vmw" (for attribute "osType") at [row,col,system-id]: [23,74,"descriptor.ovf"].

dreamy sinew
#

this channel is for jinja2 templates. i don't think what you are looking at is that

arctic sorrel
thorny perch
rugged laurel
#

supervisor -> system -> host

thorny perch
#

can i get this in to a sensor?

rugged laurel
#

Sure, there are a few guides on the forum for it

arctic sorrel
#

Got a link to the morning's chat ๐Ÿ˜‰

#

If you search @thorny perch you'll find a chat from earlier ๐Ÿ˜‰

thorny perch
#

on this channel?

arctic sorrel
#

Just search hassos version

brisk temple
#

can you if elif a delay?

arctic sorrel
brisk temple
#

would be in a script

arctic sorrel
#

Same channel ๐Ÿ˜‰

glacial sail
#

I am having a similar issue to the one in this post https://community.home-assistant.io/t/template-sensor-feedback-delay/92482 I use a broadlink RM mini 3 to turn on and off my A/C from HA and a Wyse sensor as a binary sensor to determine the current state (as it may already be turned on/off from the original IR remote). I am using a template switch but when I turn it on in HA the switch immediate returns to the off position until the binary sensor triggers and it then displays as on again. Is there any way to add a delay to the trigger from the binary sensor so it doesn't go ON -> OFF -> ON everytime I turn it on?

sinful ridge
#

I'm troubleshooting a template in the templating tool. Can I set the current time/date within the tool for troubleshooting?
{% set now() = dd:mm:yy hh:mm:ss %} I know that's not right but something like that. I want to set various times and see where my template is falling down.

charred haven
#

@glacial sail you can use the for option for the trigger so teh sensor must be on for x amount of time before the automation triggers...not sure if that is what you are looking for? more of a #automations-archived question too if thats the route you want to go.

sinful ridge
#

Ha, so my template is correct! The frontend is displaying something other than what the value template is calculating mindblown

jagged obsidian
#

is there a simpler way to compare if "somedate" isn't today compared to

{% set somedate = '2020-06-08T15:48:00' %}
{{ as_timestamp(somedate) | timestamp_custom ('%j') !=  as_timestamp(now()) | timestamp_custom ('%j') }}
sinful ridge
#

Thank you, that's what I needed. Then I could put "somedate" into my value template I was working on in place of now() to see how it would behave at different times/dates.

jagged obsidian
#

glad to be of accidental help ๐Ÿ˜„

sinful ridge
#

Turns out my issue was the value template was a time difference and it wasn't updating as often as needed. Adding in entity_id: sensor.date took care of it.

#

Haha, yes!

#

I just assume everyone is talking to me.

dull pecan
#

please could i get some help, been scratching my head all day searching the the forums. im looking to set the duration of a timer but for some reason i cant get it to recognize.

#

{{ states('input_number.cooking_hours') | int }}:{{states('input_number.cooking_minutes') | int }}:00

silent barnBOT
#

@dull pecan To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks. Here's an example:

```
code here
```
Watch the animated gif here: https://bit.ly/2GbfRJE
DO NOT repeat posts. Please edit previously posted message, here is how -> https://bit.ly/2qOOf1G

dull pecan
#
  action:
  - data:
      data_template:
        duration: '{{ states(''input_number.cooking_hours'') | int}}:{{states(''input_number.cooking_minutes'')
          | int}}:00'
    entity_id: timer.cooking
    service: timer.start```
ivory delta
#

What happens if you specify the duration in seconds instead?

dull pecan
#

@ivory delta im not sure what you mean

ivory delta
#

duration accepts either a string in the format HH.mm.ss or an integer specifying the number of seconds.

#

But I don't think that's the problem. duration should be at the same level as entity_id.

dull pecan
#

ah i see, so i was trying to use two sliders from the frontend as the timer could be used for a number of hrs

ivory delta
#
    - duration: '{{ states(''input_number.cooking_hours'') | int}}:{{states(''input_number.cooking_minutes'')
          | int}}:00'
      entity_id: timer.cooking
      service: timer.start```
Assuming it accepts a template.
arctic sorrel
#
  action:
  - data_template:
      duration: '{{ states(''input_number.cooking_hours'') | int}}:{{states(''input_number.cooking_minutes'') | int}}:00'
    entity_id: timer.cooking
    service: timer.start
``` try that
#

The problem is you had data and then data_template

#

I suspect if you look at the logs you'll find it complaining

dull pecan
#

Thanks @arctic sorrel this did the trick, i had already removed the data section before with no joy as i had read this in the forum. but this time of trying i carried out a system restart then hey presto the timer is running

ivory delta
#

Tinkerer is the king of templates (and most other things) ๐Ÿ˜ฆ

arctic sorrel
#

I can fake almost anything with enough help from the bot ๐Ÿ˜‰

dull pecan
#

Its like magic, sadly im not in the IT game and sometime struggle when it comes to the raw code aspect of it. im grateful for the help and direction

arctic sorrel
#

It's mostly just "follow the rules"

#

With the occasional dash of magic and/or chaos

ivory delta
#

Isn't most dev work magic?

#

How does it work? Wizards.

dull pecan
#

never been able to follow rules

#

๐Ÿ˜œ

gritty radish
#

I'm trying to get an average of temperatures (states('sensor1') + states('sensor2')) / 2 but it's join the two states as strings. parseInt doesn't work to add them ass ints. Any ideas?

dreamy sinew
#

dev work is sorcery

arctic sorrel
gritty radish
#

ahh, I can use float. I'll try that

#

sweet, that worked. Thanks!

thorny perch
#

Is it possible to use a variable for the target on alexa?
data:
type: tts
message: >
Here is your status update for today.
target:
{{ states('input_select.alexa_update_device') }}

arctic sorrel
#

Possibly, if correctly structured

silent barnBOT
arctic sorrel
#

You need to use data_template

thorny perch
#

doh! you're right.

#

thanks

#

i've been looking at this for hours, it's nice to have the pointer

waxen orchid
#

hey

#

i am struggling with an integer thing inside a script

#

is there anyone that can help ?

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?
waxen orchid
#

ok then

#

i have this

#
switch_on_light_office:
  alias: switch_on_light_office
  sequence:
  - data_template:
      brightness: "{% if is_state('input_number.office_light_state', '3') %} 
      255 | int
      {% elif is_state('input_number.office_light_state', '1') %}
      30 | int
      {% elif is_state('input_number.office_light_state', '2') %}
      0 | int
      {% endif %}"
    entity_id: light.bureau
    service: light.turn_on
#

not sure it s the best way to write it

#

but the intention was to make different action when i press the on button on my wall switch

#

and then i got this issue

#

expected int for dictionary value @ data['brightness']

#

and then i didn't find the key in forum and documentation

arctic sorrel
#
  - data_template:
      brightness: >- 
       {% if is_state('input_number.office_light_state', '3') %} 
        255
       {% elif is_state('input_number.office_light_state', '1') %}
        30
       {% else %}
        0
       {% endif %}
dreamy sinew
#

or

#
- data_template:
    brightness: >-
      {%- set map = {'3': 255, '1': 30} -%}
      {{ map.get(states('input_number.office_light_state'), 0) }}
#

might as well make the bot happy

#

unless that is one of the ones that is dumb and won't auto-cast the output to an int for you

waxen orchid
#

@arctic sorrel cool

silent barnBOT
#

Tinkerer is away for 20m 17s with a message :point_right: Heading towards the second star to the right

waxen orchid
#

thx

#

@dreamy sinew thx too

#

i m just discovering how input_number is working

#

and it s not as expected

#

i thought the service input_number.increment

#

would change the value according to the min and max

#

like

#
min: 1
max: 3
step: 1
#

if the value is 3 i thought input_number.increment would set the value to 1

#

but i guess its not the case

wind oriole
dreamy sinew
#

Everything under living room needs to be tabbed over by 2

wind oriole
#

thanks @dreamy sinew - spaces or tabs?

waxen orchid
#

spaces

dreamy sinew
#

Someone responded on your post with the correct answer

wind oriole
#

thanks. seems to have worked. every time I think I'm getting close on spacing something seems to throw me.

dreamy sinew
#

Friendly name, value template, and class are all properties of the living room entity

#

They need to be a level deeper than living room because of that

wind oriole
#

once you mention it it makes sense certainly - the issue is coming up with that out of my own head on the fly

#

by the way, been working on HA for a while now and have always appreciated how quite helpful and efficient the community is, so kudos ๐Ÿ™‚

gritty trench
#
  - platform: rest
    payload: '{"query":"{\r\n  Queue(date_from: \"2020-05-29 08:00:00\", date_to: \"2020-05-29 17:00:00\", ......

Can I put todays date in here somehow, instead of 2020-05-29?

dreamy sinew
#

{{ as_timestamp(now()) }}

#

Though probably need to go a bit further to pull out just the date

gritty trench
#

yeah, seems like now().strftime('%Y-%m-%d') might do the job. Although it's over midnight now, so i have to wait until 8 am to see if it works. ๐Ÿ˜’

#

Thanks.

dreamy sinew
#

Np

glacial sail
#

@glacial sail you can use the for option for the trigger so teh sensor must be on for x amount of time before the automation triggers...not sure if that is what you are looking for? more of a #automations-archived question too if thats the route you want to go.
@charred haven I use node red for my automations but I will look into automations in HA and see if I can use them to solve my problem. Thanks.

charred haven
weary heath
dreamy sinew
weary heath
#

oh my gosh thank you. I've been skimming over this document multiple times and must have missed that. Thank you!

dreamy sinew
#

Np, took me a bit to re-find it

weary heath
weary heath
#

is there any way of using a template for entity_id? I would like it to just include every person object (for example person.bob, person.jim, etc) without me having to manually update it every time a new person is added

narrow ginkgo
#

@keen smelt you can iterate states.person

weary heath
#

yes I have a template created, but i'm getting an error message because it's trying to interpret the jinja data as a string

narrow ginkgo
#

For example

{% for state in states.person -%}
  {{ state.name | lower }} is {{state.state_with_unit}},
{%- endfor %}
weary heath
#

how do I paste code in discord? Ill show you my config

silent barnBOT
weary heath
narrow ginkgo
#

Putting that into the template tester in Developer Tools works fine for me

#

What are you trying to achieve with the template?

weary heath
#

im trying to create a template variable that counts the total number of people "home" and sets it. In order to update it though, I need to set the entity_id value to each person

#

but I don't want to manually add a person each time, so I'm trying to do a template for it

narrow ginkgo
#

entity_id optional for templates - it's usually able to be automatically implied based on the template which entities will trigger a refresh

weary heath
#

It's not for my case though, which is why I'm doing this

narrow ginkgo
#

entity_id doesn't itself support templates, so you'd need to hard code it

weary heath
#

that's what I was thinking, but I wanted to see if there was another option

narrow ginkgo
#

Let me check the code for the template helper, it should be able to pick up that states.person depends on all active person entities

dreamy sinew
#

You need to drill down to a specific entity

#

The code is looking for states.domain.entity_id or states(entity_id) specifically

#

You can't iterate over a list of IDs either

#

If you can't do that, listing out your entities via entity_id: will ensure it will update when any of those entities changes

weary heath
#

what do you mean by drill down to a specific entity?

dreamy sinew
#

Via the 2 methods in the line that came right after that comment

#

I'm on mobile so I don't want to type that out again

narrow ginkgo
#

in other words - you'll have to hard code entity ids either in the template or in entity_id, so take your pick ๐Ÿคทโ€โ™‚๏ธ

weary heath
#

ah i get it now

#

that's kinda a crummy situation, but it makes sense

dreamy sinew
#

The watcher needs something deterministic for performance reasons

weary heath
#

so a template would be to resource heavy?

dreamy sinew
#

It can be if you're bad and write a template that hits literally every entity

#

This is a way to take the shotgun away

#

You still have a sharp ax though. You just can't shotgun your foot off

weary heath
#

but I'm trying to hunt a bear

#

๐Ÿ˜ฆ

narrow ginkgo
#

๐Ÿคฃ to be fair I can't imagine you're creating and removing new person entities every day?

weary heath
#

no I'm not but I'm the kind of person that loves automating things even if I do them once

#

and this project is teaching me a lot about templating so I'm just testing my options at this point

#

thank you guys!

dreamy sinew
#

Np!

#

There are some hacks that can be done but you're still listing out every entity somewhere

narrow ginkgo
dreamy sinew
#

Pulled from one of mine

weary heath
#

phew that last line shows me I need to understand filters a bit more haha

dreamy sinew
#

Lol

#

The reject was a recent addition. The battery in one of my sensors died and it tanked the average

#

Note that in the list of sensors I'm doing the states() call on the entity directly. If you don't do it that way, you'd have the same problem

#

I found that the hard way

weary heath
#

yeah I was having trouble with that because those functions for my application (where I didn't have any direct references because it was looping through states.person) I couldn't do it that way

#

unless I missed something

dreamy sinew
#

Yep, that's the issue

weary heath
#

but states.person shouldn't "go offline"

#

hopefully... lol

dreamy sinew
#

states.person isn't an entity though

#

states.person.person_1 would be

weary heath
#

true thats what I meant

dreamy sinew
#

Also, protip use states('person.person_1') as much as possible

weary heath
#

yeah I totally will when I'm configuring definite things

dreamy sinew
#

If you use the other method and the entity doesn't exist on startup ha will throw exceptions

#

states() will just return unknown

weary heath
#

thats really convenient

sinful ridge
#

If im doing a value template that take differences of times I need an entity to trigger the value to calculate it on a regular basis. But what about when using the template editor in dev tools? Is it constantly reevaluating time or do I need to manage that somehow?

arctic sorrel
#

Every time you edit the template there it updates the template

#

So, adding a space causes it to be updated

sinful ridge
#

Cheers, good to know.

worn nova
#

Im using the below in an automation, is there a way to format the text of the friendly name to use all or partial capital letters?

message: "Check: {{ state_attr(trigger.entity_id, 'friendly_name') }}"

dreamy sinew
#

|title

worn nova
#

Im assuming like below?
message: "Check: {{ state_attr(trigger.entity_id, 'friendly_name|title') }}"

dreamy sinew
#

no

#

state_attr()|title

worn nova
#

@dreamy sinew tested and functions as expected. thanks!

pearl bough
#

Currently, my setup: I am sending this:
curl -d 'testdata=1' -X POST https://[mydomain]/api/webhook/testy

Which works if i have no condition. I am trying to setup the condition per the docs ( whcih don't mention how to parse the data coming in from the web hook in the Conditions, Automation templates, and Automation conditions pages that I can see, if i am blind, please correct me.) with the following condition:

condition: template
value_template: '{{ state_attr("trigger.data", "testdata") < 4 }}'```
#

also tried using curl -d '{"testdata":"1"}' and swapping out for trigger.json with no luck. What am I doing wrong?

nocturne chasm
#

@pearl bough , you will prob get more help sharing the whole automation

silent barnBOT
pearl bough
#

sure, one sec

buoyant pine
#

Try "{{ trigger.data['testdata'] | int < 4 }}"

#

@pearl bough โ˜๏ธ

#

Scared them away I guess ๐Ÿ˜ข

nocturne chasm
#

He is prob trying it ๐Ÿ‘๐Ÿป

pearl bough
#

Juggling work and this ๐Ÿ™‚

#

one sec, lemme try

#

Wooo, that works perfectly

buoyant pine
#

Yeah I'm jk lol

pearl bough
#

Hm, is the syntax different for json?

buoyant pine
#

For trigger.json? Prob the same

pearl bough
#

trying {{ trigger.json['testdata'] | int < 4 }} with curl -d '{"testdata":"1"}' doesn't seem to work

#

hm, maybe i need to pass on an explicit json content type, sec

#

that didn't work.

#

tried: curl -H "Content-Type: application/json" -d '{"testdata":"1"}'

#

oh wait, i'm a dingus

#

i forgot to hit save

pearl bough
#

However, just redid some testing

#

I need that Content-Type header added for the trigger.json to behave

buoyant pine
#

Makes sense

pearl bough
#

Fun fun fun, now i can make various web stuff of mine trigger stuff ๐Ÿ˜„

#

ty for the pointers!

buoyant pine
#

Have fun!

#

But not too much fun

nocturne chasm
#

Donโ€™t do anything Tediore wouldnโ€™t do. ๐Ÿคฃ

winged dirge
#

Would I need a template cover to extra data from this 19:35:13 {"TuyaReceived":{"Data":"55AA0307000507040001001A","Cmnd":7,"CmndData":"0704000100","DpType4Id7":0,"7":{"DpId":7,"DpIdType":4,"DpIdData":"00"}}}

#

debating if I can get away with MQTT cover

short jolt
#

Hi all,
I'm checking my sensors template but don't find the mistake

#

if anyone as an idea?

#
- platform: template
  sensors:
    prod_sma_actuelle_watt:
      value_template: >
        {{ states.sensor.sma_power_absorbed.state - states.input_number.prod_minuit.state }}
      unit_of_measurement: 'W'
arctic sorrel
#

It might help if you were to explain the problem ๐Ÿ˜‰

short jolt
#

yep sorry

#

i try to put screenshot

#

but impossible to paste

arctic sorrel
#

That's because too many people have thought that sharing text as image is a good thing

#

It's not

short jolt
#

input_number.prod_minuit : 33334714.0

silent barnBOT
short jolt
#

sensor.sma_power_absorbed : 33335460.0

arctic sorrel
#

You've tested the template โ˜๏ธ ?

short jolt
#

sensor.prod_sma_actuelle_watt : unknown

#

i didn't test

#

will check didn't know that possibilities

short jolt
#

but it's not in automation , this is in sensor template

#

@arctic sorrel in templates to test i enter :

#
today prod is {{ states.sensor.sma_power_absorbed.state - states.input_number.prod_minuit.state }}

response : unknown error rendering data

arctic sorrel
#

There you go - your template isn't valid ๐ŸŽ‰

#
{{ states('sensor.sma_power_absorbed')|int - states('input_number.prod_minuit')|int }}
``` Try that
short jolt
#

it works !

#

thanks i'm a noob since i use home assistant since 2 weeks now .. ๐Ÿ˜ฆ

#

thank you very much

arctic sorrel
#

No worries

short jolt
#

good to know that i can test before to use, many times to win ๐Ÿ™‚

#

thanks from belgium ๐Ÿ™‚

worn nova
#

Hi, trying to setup an automation that notifies me of updates to home assistant and hacs via a template. is there a way to combine this and show both If available? I am currently using the below and it is only showing hacs and not the current home assitant update.

  message: 'Check: {{ state_attr(trigger.entity_id, ''friendly_name'')|title }}'
  title: Update Available
service: persistent_notification.create
winged dirge
#

Anyway to invert 0-100 to 100-0 scale

#

i.e. 2 -> 98

#

5 -> 95

#

It would be f(x)=100โˆ’x

#

I'll think this is it:
{{ 100 - states('sensor.living_room_blind_position') | int}}

#

It is ๐Ÿ˜„

winged dirge
#

Can "this" be used with templates to remove to the current state of the object?

mighty ledge
#

you'd ahve to make a template sensor

granite steppe
#

I am trying to pull the 'status' attribute from my robot vacuum for an automation. This is what I have so far, but it does not seem to be working. I've tried for a few hours tweaking... but hoping its something obvious? {{ state_attr('vacuum.robovacโ€™,โ€™statusโ€™) == 'cleaning' }}

jagged obsidian
#

is "cleaning" ?

#

granted cleaning is one of the statuses

#

what exactly are you trying to get?

arctic sorrel
#

"smart" quotes

#

๐Ÿคฎ

#
{{ state_attr('vacuum.robovacโ€™,โ€™statusโ€™) == 'cleaning' }}
                             ^ ^      ^
granite steppe
#

yeh, idle or cleaning. I'm trying to do an automation, basically
Trigger: When battery is below 60%
Trigger: When status is โ€˜returningโ€™
Trigger: When status is โ€˜cleaningโ€™
Action: Turn on Eufy Power Plug

silent barnBOT
arctic sorrel
#

Fix the "smart" quotes and then test ๐Ÿ˜‰

granite steppe
#

Ohhh, how on earth did i not notice that! haha. My eyes are going square!

arctic sorrel
#
{{ is_state_attr('vacuum.robovac','status','cleaning') }}
jagged obsidian
#

what are "smart" quotes?

arctic sorrel
#

โ€™

#

That's one - they're "human friendly"

granite steppe
#

thanks @arctic sorrel - works perfectly.

#

I'll note for next time haha

arctic sorrel
jagged obsidian
#

i'm also blind, i dont see the difference .D

granite steppe
#

you gotta look closely.... it kinda has a little dot at the top

arctic sorrel
#

Anybody using a word processor will get โ€œsmartโ€ quotes

granite steppe
#

but so easy to miss

arctic sorrel
#

As opposed to "simple" quotes

granite steppe
#

but now i know, i'll definitely watch out for those

arctic sorrel
#
โ€œ " โ€
jagged obsidian
#

ah now i know what you mean... still didn't spot that difference ๐Ÿ˜„

#

time to get new glasses

arctic sorrel
#

๐Ÿ˜„

granite steppe
#

Me: time to get new eyes

buoyant pine
#

my brand!

arctic vortex
#

I have a problem with rounding my template sensor.

#

That is a there is a problem in the system statement

ivory delta
#

Ok

#

What have you tried and what is it doing?

glacial root
#

Hello, coming ove rfrom automations ๐Ÿ˜›

#

im trying to trigger an automation based on a template.

#

I have a helper type input_datetime that only uses time

#

and i created a sensor sensor.time

#

but the sensor.time outputs time as H:M

#

and my helper outputs in H:M:S

#

now im unable to compare those in a template

silent barnBOT
#

@meager orchid To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks. Here's an example:

```
code here
```
Watch the animated gif here: https://bit.ly/2GbfRJE
DO NOT repeat posts. Please edit previously posted message, here is how -> https://bit.ly/2qOOf1G

hollow bramble
#

that's a new one

dreamy sinew
#

yup

#

probably held shift

#

on us keyboard at least

arctic sorrel
meager orchid
#
  - platform: template
    sensors:
      shower_hum_over_eighty:
        friendly_name: "Shower Humidity Over 80%"
        value_template: >-
          {% if states('sensor.bath_humidity') | float > 80 %}
          on
          {% else %}
          off
          {% endif %}
glacial root
#

so i probably have to use strptime ? @arctic sorrel

meager orchid
#

There we go - not suer what happened. Anyway - I can't get this sensor to turn on - despite the humidity going above 80%

dreamy sinew
#

you using a sensor or a binary sensor?

meager orchid
#

binary

dreamy sinew
#
value_template: "{{ states('sensor.bath_humidity')|float > 80 }}"```
meager orchid
#

so just nix the % symbols and put the whole line in quotes?

arctic sorrel
#

Exactly as shown there - replaces your 6 lines

meager orchid
#

ok thanks - any idea why my version works in the Templateing section - but not in "real life"?

dreamy sinew
#

binary sensor is expecting true/false

#

which you can do via your method but its not necessary

meager orchid
#

ok great, appreciate the assist

hexed falcon
#

I think this is where this belongs but I have imperial units selected in the UI as my default which is what I want for everything expect the Temps from my Netdata integration which I want in Celsius. Other than template is there an easy way to do this?

glacial root
#

@arctic sorrel i managed to get it to work. It ain't pretty. but it works:

- platform: template
    value_template: '{% if states(''sensor.time'') == (states(''input_datetime.wanneer_nieuwe_herinnering'')[0:5])
      %}true{% endif %}'
arctic sorrel
#

Eh, if it works... it's not how I'd have done it, but it's valid ๐Ÿคท

glacial root
#

haha, well i wanted to use strptime but couldn't get it to work

#

Could you tell me how you would have done it? so I can learn from that?

arctic sorrel
#

I'll dig out an example later and ping you when I've got it ๐Ÿ‘

glacial root
#

thx! ๐Ÿ™‚

#

21:49 (this was the string from sensor.time)
21:22:00 (this was the string from input_datetime.wanneer_nieuwe_herinnering)

arctic sorrel
#
{{ states('sensor.time') == state_attr('input_datetime.wanneer_nieuwe_herinnering','timestamp')|timestamp_custom("%H:%M") }}
dreamy sinew
#

@hexed falcon you get a choice of imperial or metric for the entire system. you can't change individual entities

hexed falcon
#

That's what I thought that sucks! Guess I'll just trick it with a template then

gloomy bear
#

Could anyone help me configure a template switch to effectively change the domain of a light? I want to create a template switch which simply turns a light on/off but will be considered a "switch" instead of a "light."

#

`# Switches from samsung plugs that appear as lights
switch:

  • platform: template
    switches:
    Bedroom Fan:
    turn_on:
    service: light.turn_on
    data:
    entity_id: light.on_off_output_4
    turn_off:
    service: light.turn_off
    data:
    entity_id: light.on_off_output_4`
#

That is what I attempted but isn't working

dreamy sinew
#

Should be fine

gloomy bear
#

I have never made a template before, so literally all I've done is plop that into my config.yaml, not sure if I need to do something more... I got a config error on restart

#

I'm trying to do a more simple version now like this `# Switches from samsung plugs that appear as lights
switch:

  • platform: light
    name: "Bedroom Fan Samsung"
    entity_id: light.on_off_output_4`
#

Also doesn't seem to work

dreamy sinew
#

Oh, I see. Change Bedroom Fan: to bedroom_fan:

gloomy bear
#

So if this worked I should see a new entity named "bedroom_fan" which is a switch and controls that light called light.on_off_output_4 right?

dreamy sinew
#

Yup

gloomy bear
#

It told me `The following integrations and platforms could not be set up:

switch.template
Please check your config.`

dreamy sinew
#

Bot is ded

gloomy bear
#

lol

silent barnBOT
#

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

dreamy sinew
#

There we go

muted berry
#

So I'm trying to create a template where the input value from a temp sensor, dictates the fan speed of my hvac. Does this look ok?

harsh tiger
#

Hey folks, is there any easy way to translate this to german:
{{ now().strftime('%A') }}

buoyant pine
#

@muted berry the temperature checks should be in ascending order. The way you have it now, if the temperature is 22, it'll set the fan mode to 4. I also don't see a service there but I'm guessing you just didn't include it in the paste

muted berry
#

So you mean I should invert the entire thing?

buoyant pine
#

Yeah, should be if temp < 22 ... elif temp < 23 ...

#

The template is evaluated from top to bottom and stops when it meets one of the tests

muted berry
#

action:

  • data:
    entity_id: climate.overvaningen
    fan_mode: '{% set temp1 = states(''sensor.temperature_5'')|float %} {% if (temp1
    < 22 %) } 2 {% elif (temp1 < 23 %) } 3 {% elif (temp1 < 24 %) } 4 {% else
    %} 2 {% endif %}'
    service: climate.set_fan_mode
#

So, like this?

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

buoyant pine
#

Also make it a multi-line template like how you had it in your original paste

#

Oh and this:

{% if (temp1 < 25 %) }
``` should be

{% if temp1 < 25 %}

muted berry
#

I did that but unfortunately it returns an error

#

here's exactly what's in the automations file

buoyant pine
#

Read my previous message

muted berry
#

I did, and corrected the paste

buoyant pine
#

There's also still no service call

muted berry
#

sec

#

had to reopen the file

#

the formatting is completely messed up when pasting the template via the ui

buoyant pine
#

Yeah, don't use the UI for templates

muted berry
#

how should the formatting be made correctly?

buoyant pine
#

Might work if you choose Edit as YAML in the overflow menu in the UI though

muted berry
#

for the actual template part

buoyant pine
#

The way you had it in the original paste, plus my corrections

muted berry
#

"action:

  • data_template:
    entity_id: climate.huvudvaningen
    fan_mode: >-
    {% set temp1 = states('sensor.huvudplan_2')|float %}
    {% if (temp1 < 22 %) } 2
    {% elif (temp1 < 24 %) } 3
    {% elif (temp1 < 24 %) } 4
    {% else %} 2
    {% endif %}"
#

oooh

#

nevermind

#

just saw lol

buoyant pine
muted berry
#

action:

  • data_template:
    entity_id: climate.huvudvaningen
    fan_mode: >-
    {% set temp1 = states('sensor.huvudplan_2')|float %}
    {% if temp1 < 22 %} 2
    {% elif temp1 < 23 %} 3
    {% elif temp1 < 24 %} 4
    {% else %} 2
    {% endif %}
#

there we go

buoyant pine
#

Do you have a service call in there too?

muted berry
#

yes

arctic sorrel
#

~share @muted berry

silent barnBOT
arctic sorrel
#

Please use a code share site to share the whole thing, so we don't have to play guess if the formatting is valid or guess if the construct is valid

muted berry
#

Yes sir

#

whoops

#

this is the correct one

silent barnBOT
arctic sorrel
#

Did you test the template?

muted berry
#

yes

arctic sorrel
#

And the fan modes are 2, 3, 4?

muted berry
#

yes

#

at least the ones I want to trigger

#

and this is the output

#

action:

  • data_template:
    entity_id: climate.huvudvaningen
    fan_mode: >-

     2
    
#

from the template test

arctic sorrel
#

Then the template is valid

muted berry
#

and the automation works!

#

ugh..or not

#

or rather, the behavior is incorrect

quick cape
#

hi - I've been stuck on this one for a bit now. Trying to get the nr of hours and nr of minutes from a duration sensor (from the history_stats integration) to calculate the total nr of minutes duration. So the sensor outputs something like '6h 35m' instead of 6:35 and I would like to extract 6 and 35 to calculate 395.
{{state_attr('sensor.filtered_today_hrs','value').split(':')[1]}} would have worked if the format was 6:35 but doesn't work on '6h 35m'. Is there an elegant way fo doing this?

jagged obsidian
#
{% set filtered = "6h 35m" %}

{% set hours = filtered.split('h ')[0] %}
{% set min = filtered.split('h ')[1].replace('m','') %}
{{ hours|int*60 + min|int }}

@quick cape how bout this, first line is just setting the variable

buoyant pine
#

@quick cape the actual state of a history stats sensor that's calculating time is a float in hours, so you could just make a template sensor with this as the value_template if you want to convert it to minutes:

"{{ states('sensor.filtered_today_hrs') | float * 60 }}"
mighty ledge
#

Seems like that needs to be updated to have a timestamp

#

with a ts device class

edgy dirge
#

how do i specify value template if my sensor value is between 0 to 1.94 using is_state?

#

currently i use this {{ 1.94 > states('sensor.genset_light_intensity_2') | float > 0 }}

#

but want to use is_state

buoyant pine
#

You can't

edgy dirge
#

using is_state as follows {{ 1.94 > is_state('sensor.genset_light_intensity_2') | float > 0 }} gives error Unknown error rendering template

buoyant pine
#

Why do you want to use is_state()?

edgy dirge
#

i need is-state if my anolog sensor goes uniavilable my template also goies unknown or unavailable

#

i read in documentation as follows

#
If you are using the state of a platform that takes extra time to load, the Template Binary Sensor may get an unknown state during startup. This results in error messages in your log file until that platform has completed loading. If you use is_state() function in your template, you can avoid this situation. For example, you would replace {{ states.switch.source.state == 'on' }} with this equivalent that returns true/false and never gives an unknown result: {{ is_state('switch.source', 'on') }}```
buoyant pine
#

you'll be fine with what you have

jagged obsidian
#

but is_state requires a state

#

to know whether it is or isn't

buoyant pine
#

what you have will return False if the entity doesn't exist or is unavailable

jagged obsidian
#

he can use if else statement if he really really wants to be sure ๐Ÿ™‚

buoyant pine
edgy dirge
#

I was unable to add default state or initial state to sensor also

buoyant pine
#

those aren't valid options for a binary template sensor

edgy dirge
#
          {{ 200 > states('sensor.genset_light_intensity_2') | float > 0 }}```
#

i have added availabilty already

#

this is my full config

silent barnBOT
edgy dirge
#
        friendly_name: "Binary Lux Power Sensor"
        device_class: power
        value_template: >-
          {{ 1.94 > states('sensor.genset_light_intensity_2') | float > 0 }}
        availability_template: >-
          {{ 200 > states('sensor.genset_light_intensity_2') | float > 0 }}```
buoyant pine
#

i think you're fine then. if sensor.genset_light_intensity_2 is unavailable or out of the range the template sensor will be unavailable

#

in fact, you could test that by going to developer tools > states and changing the state of sensor.genset_light_intensity_2 to unavailable (or really any word)

edgy dirge
#

Assume analog sensor is in OFF state & due to wifi issue anlog sensor goes unavailable i see this binary sensor goes unavailable Then to OFF again. Hence my automation is triggred twice

#

but actually its OFF & no automation to be triggered

jagged obsidian
#

make automation use from on to off only

edgy dirge
#

make automation use from on to off only
@jagged obsidian I agree but its OFF to unavailable to OFF HA tiggers unavailable to OFF as off trigger

buoyant pine
#

that shouldn't if you make the automation use

from: 'on'
to: 'off'
``` like blakadder is saying
edgy dirge
#

actually its no change OFF to unavailable to OFF = OFF state only

buoyant pine
#

let's see the automation

silent barnBOT
buoyant pine
#

i'm having trouble understanding the issue you're experiencing

edgy dirge
#

my automation is in nodered

buoyant pine
#

and you want the automation to trigger when the sensor goes from on to off?

edgy dirge
#

on to off automation 1

#

off to on automation 2

#

am ok to switch the automation to HA as well

buoyant pine
#

well i don't know node red, but if it's set up to only trigger from on to off or off to on then unavailable to off shouldn't trigger (or off to unavailable)

edgy dirge
#

ok got it ill give it a try thanks

#

in HA automations

#

@buoyant pine Thanks

buoyant pine
#

no prob

#

or you can correct the node red automation

edgy dirge
#

@buoyant pine actually am using the template binary sensor to find if my home is running on genset or power line (Basically power outage monitor). wen Genset on an LED glows in my panel which the LDR reads a Anlog value am converting that anolog value into binary template sensor as ON & OFF.

#

When there is a power outage the binary template sensor acts this way before power outage its OFF - when power outage it becomes unavailabe (For say 5 -15 sec) - Then it changes to ON

#

hence OFF-unavailable ON = automation 1

#

Similary ON - unavailable - OFF = automation 2

#

but ON - unavailabe - ON or OFF - Unavailable - OFF is not poweroutage its just a wifi disconnection or esp reboot

#

hope it explains my problem

buoyant pine
#

ah i see what you mean

edgy dirge
#

Any solution possible?

ivory delta
#

Couldn't you represent the previous state in an input_boolean? Only update the input_boolean when the new state isn't 'unavailable'.

mighty ledge
#

@edgy dirge make a template sensor that use's the previous state if unavailable

- platform: template
  sensors:
    powerline:
      value_template: >
        {{ states('binary_sensor.powerline') if states('binary_sensor.esp_powerline') in ['unknown','unavailable','None'] else states('binary_sensor.esp_powerline') }}
pine musk
#

{{ states('weather.home')}}

#

gives me Sunny

#

what I want is temperature & humidity

ivory delta
#

Then you want the state attributes, not the state itself.

#

{{ state_attr('weather.home','some_attribute_here') }}

#

You can see the attributes of an entity if you go to devtools > States and pick your entity.

pine musk
#

got it

#

so like this?

#
  - platform: template
    sensors:
      weather_temp:
        friendly_name: "Temperature"
        entity_id: weather.home
        value_template: "{{ state_attr('weather.home','temperature') }}"
ivory delta
#

Looks okay. Try it out and see what the config check says

silent barnBOT
#

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

pine musk
#

template works there, just tring to build a sensor

#

ok, sensor works for humidity, but not for temp

ivory delta
#

Do you have them both defined in the same file?

pine musk
#

yes

silent barnBOT
ivory delta
#

Share the config for both (and any related ones you added with them)

pine musk
#

only difference is replacing the word temperature with humidity

ivory delta
#

And the entity definitely had an attribute for temperature? What's the sensor doing?

pine musk
#

yes, its weather.home . in the template tester, it works

ivory delta
#

Uh... that's wrong ๐Ÿ™‚

#

Did you run the config checker?

pine musk
#

what's wrong with it?

ivory delta
#

The checker will tell you

#

Get used to running it every time you make changes

arctic sorrel
#

You may also want to compare what you did with the examples in the docs

pine musk
#

can't get a cmd prompt in docker

#

to run checker

ivory delta
#

There are multiple ways to run it. For now, try the UI checker.

pine musk
#

ui checker says fine

silent barnBOT
#

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

ivory delta
#

Haha, prime example of why the command line one is preferred.

arctic sorrel
#
sensor:
  - platform: template
    sensors:
      solar_angle:
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"
      sunrise:
        value_template: "{{ state_attr('sun.sun', 'next_rising') }}"
``` From the docs
pine musk
#

aha

ivory delta
#

๐Ÿ˜‰

#

Easy once you spot it

#

YAML has list items (which are preceded by a hyphen) and dictionary items (which are not). Can't have a duplicate dictionary key.

pine musk
#

i understand what happened.

high lichen
#

I am using the OpenSprinkler integration and I made an input slider to set the runtime seconds as well as a button that calls the opensprinkler.run service. This is my code for the button : type: button tap_action: action: call-service service: opensprinkler.run service_data: entity_id: switch.s01_station_enabled run_seconds: '{{ states("input_number.runtime_zone1") | int }}' entity: switch.opensprinkler_enabled but I get this error when clicking the button Failed to call service opensprinkler/run. expected a list for dictionary value @ data['run_seconds']

#

Any ideas ^

#

?

ivory delta
#

The problem is the template still, chaotik. Test it in devtools > Templates

#

It doesn't recognise whatever it's evaluating to.

high lichen
#

hehe.. sorry.. I thought you meant to try in the template room ๐Ÿ™‚

#

I see what you mean now.

ivory delta
#

Nope. devtools = Developer Tools

high lichen
#

got it ๐Ÿ™‚

ivory delta
#

This channel's probably better for this conversation anyway, tbh.

high lichen
#

so this '{{ states("input_number.runtime_zone1") | int }}' returns the right value (i.e. the integer with single quotes around it though)

#

if I remove the single quotes, then I get the clean integer

#

However, when I same it without the single quotes, it replaces the code with '[object Object]': null

ivory delta
#

In the template dev tool, you don't need quotes around it. In anything else, you do.

#

So your code should have run_seconds: '{{ states("input_number.runtime_zone1") | int }}'. It needs the quotes just so whatever reads the YAML knows where the template starts and ends but it'll throw them away and only evaluate {{ states("input_number.runtime_zone1") | int }} (which is your integer).

#

If you put a template into something without the quotes, you get that stupid object Object nonsense. Which... sounds suspiciously like a JavaScript thing to me. What card is this going in?

dreamy sinew
#

That's how the front end tries to represent a dictionary

high lichen
#

right now it's just a button card. After I get it to work, I'd want it as a entity button row

little gale
#

How do I deduct a sensor value from 100?

ivory delta
#

A minus sign usually works well for subtraction

arctic sorrel
#

You've already got one that divides, you can use that as the base

#

states('sensor.internal_media_used') gives you the value, subtract it from 100

little gale
#

uhhh what would that look like?

arctic sorrel
#
{{ thing - other_thing }}
``` standard basic maths
#

Replace thing with 100 and other_thing with the relevant states()

little gale
#

yeah except that said unknown in the template editor

arctic sorrel
#

that wail

#

I did a thing, it didn't work, why ๐Ÿคฆ

#

You should know by now... you need to show us the code

#

Much much better to tell us what you've done, what the problem is, and what your goal is than ask questions that make it sounds like you don't know basic maths ๐Ÿ˜‰

little gale
#

template editor is broken. States shows the correct percentage but template editor says unknown:
{{ states('sensor.disk_free_percent_merged')}}

arctic sorrel
#

Then that entity doesn't exist

little gale
#

yeah it does

arctic sorrel
#

Go on, screen shot please ๐Ÿ˜‰

silent barnBOT
#

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

arctic sorrel
#

Somebody failed their reading test

#

free != use

rare panther
#

or I guess copy-pasted wrong sensor name!

arctic sorrel
#

Well, that would appear to exist ๐Ÿค”

#

Did you copy and paste the entity?

little gale
#

to the template editor?

#

yes I did from the config file

arctic sorrel
#

Did you copy and paste the entity from States?

little gale
#

no

arctic sorrel
#

Try that

#

That'll rule out a typo

little gale
#

just did, same thing

arctic sorrel
#

Then something weird as hell is going on with your system...

little gale
#

yeah its cursed I know

rare panther
little gale
#

Yeah I created my own

#

Kinda wish there was though ๐Ÿ˜…

rare panther
#

then you do your maths of 100- disk_use_percent!. So next time, do double check before making claims of "template editor does not work" ๐Ÿ™‚

little gale
#

no, that was for another sensor:
sensor.network_health_1h

#

which I still need help with

#

then you do your maths of 100- disk_use_percent!. So next time, do double check before making claims of "template editor does not work" ๐Ÿ™‚
What? The issue persists, I'll reboot it at the end of the day to see if it fixes it or not

#

also not really a claim, I did send screenshots

rare panther
#

you created your own sensor which has incorrect math probably. You could have just used{{ 100 - states('sensor.disk_use_percent')|int }}

little gale
#

that int at the end fixed the actual issue

rare panther
#

well, it was not an issue in the first place, just your understanding of the usage ๐Ÿ™‚

little gale
#

well it was, to me

#

with that logic, everything is a non issue if everyone knows everything

arctic sorrel
#

The output of states is a string

rare panther
#

with that logic, everything is a non issue if everyone knows everything
dunno about your logic, but if you have not read the docs or not know something, then the logic of stating something is broken is incorrect IMHO

vapid pumice
#

i am trying out the crypto sensor that scraps the values.. how do I create a template that takes the value of a coin and then mutiplies it by how many coins you have in a template?

ivory delta
#

{{ x * y }} (I'll let you substitute x and y)

vapid pumice
#

how do you put that into the configurations.yaml file?

#
    cryptocurrency_name: "bitcoin"
    currency_name: "aud"
    update_frequency: 1
    value_template: '{{ value_ }}'```
#

or am i missunderstanding how all this template stuff works?

ivory delta
#

Well that's not a built-in integration. Are you using a custom component?

vapid pumice
#

yes

ivory delta
#

And what do the instructions say?

vapid pumice
#

absolutly nothing

#

i added the line value_template

#

i duno how else to work it?

ivory delta
#

Forget your solution for now. What does that custom component do? Does it create sensors for you? Is it just a UI thing?

vapid pumice
#

it creates sensors for you

buoyant pine
#

You'd need to make a template sensor that multiplies number of coins by the unit price

ivory delta
#

So use those sensors and create a custom sensor wrapping it.

#

You can more or less copy the first example and change the template and names.

vapid pumice
#

ahh ok.. let me give that a try.. that's the part of understanding i was missing

ivory delta
#

You can't just add whatever you like to an integration. They all have a pre-defined set of values they'll accept. Start with what you know, don't just guess ๐Ÿ˜‰

vapid pumice
#

Colonal Klink said it best: "I KNOW NOTTHING!"

#

would this be correct?: - platform: template sensors: friendly_name: "Bitcoin Owned" unit_of_measurement: '$' value_template: '{{ value_sensor.cryptoinfo_bitcoin_aud * 0.1234 }}'

ivory delta
#

You haven't given it a name

#

Pay attention to the nesting of the example:

sensor:
  - platform: template
    sensors:
      solar_angle:
        friendly_name: "Sun angle"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"
#

solar_angle is the name of the sensor, 'Sun angle' is the friendly name. You must provide the first, the second is optional.

vapid pumice
#

like this? - platform: template sensors: crypto_bitcoin_owned: friendly_name: "Bitcoin Owned" unit_of_measurement: '$' value_template: '{{ value_sensor.cryptoinfo_bitcoin_aud * 0.1234 }}'

#

ok ta

ivory delta
#

Nee bosh

thin furnace
#

im confused on calling a service with a template. the template I have created below does return the string "fireworks" but for some reason its not interacting withe the wled client.

#
entity_id: light.wled_2
intensity: 100
speed: 10
effect: >
  {{state_attr('calendar.holidays_for_lights' , 'message')}}
#

when i call service "effect.wled" with the template removed and the string "fireworks" it properly communicates with the wled integration

arctic sorrel
#

value_sensor.cryptoinfo_bitcoin_aud is a string @vapid pumice - states('value_sensor.cryptoinfo_bitcoin_aud') is the state of that entity

states('value_sensor.cryptoinfo_bitcoin_aud')|float would be a number you could use

#

@thin furnace Helps if you share the whole thing, so we can tell what you've overlooked - like Rule #1 or Rule #2 (see the topic)

vapid pumice
#

@arctic sorrel cheers.. I was just trying to figure that out.. but I get 0.0 now instead of unknown

arctic sorrel
#

Well, test it all out ๐Ÿ˜‰

vapid pumice
#

value_template: "{{ states('value_sensor.cryptoinfo_bitcoin_aud')|float * 0.1234 }}"

arctic sorrel
#

What does

#
{{states('value_sensor.cryptoinfo_bitcoin_aud')}}
``` show?
vapid pumice
#

unknown

arctic sorrel
#

There's a problem ๐Ÿ˜‰

#

Check devtools -> States to ensure you're not making up an entity

vapid pumice
#

if I remove "value_" i get the value

arctic sorrel
vapid pumice
#

now how do i round it to 2 decimal places

buoyant pine
#

| round(2) but you need to put what you currently have in parentheses otherwise you'll only round the 0.1234

vapid pumice
#

ok i'll give it a go

thin furnace
#

@arctic sorrel maybe this is the wrong channel since i know the template works as the template returns the correct string in the developer/templating tab. I am only working in the call service tab currently, I dont see what else I can share a this point.

arctic sorrel
#

How about the whole automation/script/whatever?

silent barnBOT
thin furnace
#

ill create a script and share it

arctic sorrel
#

Wait a second

#

Is that snippet above all you've done?

thin furnace
#

yes

arctic sorrel
#

That, by itself, won't do anything

thin furnace
#

sorry my son distracted me

arctic sorrel
#

It needs to be in a service_data block (see Rule #2)

thin furnace
#

@arctic sorrel for some reason when i was playing around wiht this last night i went down that road and kept getting errors, i guess it was too late for me. got it working now was soo simple.

#

thanks again

#

first time with templating and service calls.... obviously lol

junior stratus
#

Hallo all
I've a probably small question where I need your help:
I created a template sensor that returns a value between 0 and 1
Now I want to use this value in another sensor, but set this sensor as a value will just return 0
{% set f = state_attr('sensor.light_factor', 'value') | float %}
{{ f }}
also tried following with no luck
{% set f = states('sensor.light_factor')| float %}
can you help please?

buoyant pine
#

Does sensor.light_factor exist?

junior stratus
#

yes {{ states('sensor.light_factor') }} returns the value

#

return "value: 0.21594674897802127"

buoyant pine
#

What do both templates you've tried show at developer tools > template?

junior stratus
#

sensor.light_brightness value: 20.0 f: 0.0
v: value:

0.21594674897802127
x: None
friendly_name: Lichthelligkeit
sensor.light_factor value: 0.21594674897802127 friendly_name: Tageslicht Faktor

#

x: >-
{{ state_attr('sensor.light_factor', 'value') }}

buoyant pine
#

Just put

{{ states('sensor.light_factor') }}

{% set f = states('sensor.light_factor')| float %}
{{ f }}
junior stratus
#

f is still 0.0

buoyant pine
#

Let's see a screenshot of developer tools > template with what I showed you in it

silent barnBOT
#

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

buoyant pine
#

Not at all what I asked to see

junior stratus
#

? both commands are attributes of light_brightness
Or did I got you wrong?

#

wait now I might have understood

buoyant pine
#

Wait. Why do you have value: under value_template:?

#

That's your problem

junior stratus
buoyant pine
#

Yeah, remove value: from under value_template: in the template sensor config

#

That's making the state of that sensor start with value: which is not what you want

junior stratus
#

It WORKS!!! I would never have found this! Thank you so much!

buoyant pine
#

No prob, but I'm wondering where you got the idea to put value: there too

#

Just wondering if something was misleading in the documentation

junior stratus
#

kinda from
data_template:
message: >
but somehow I must have misread there something.

buoyant pine
#

Oh gotcha. In an automation, data_template: replaces data: when one of the other pieces of service data (message: for example) contains a template

zinc bloom
#

Looking for some guidance how to extract forecast from a weather sensor
The attributes look like this:

- datetime: '2020-06-14T00:00:00'
temperature: 21.1
templow: 9.1
condition: partlycloudy```
How can I get the forecast --> condition string?
ivory delta
#

When you say a weather sensor, do you mean the device or an actual sensor in HA?

zinc bloom
#

an actual sensor - weather.smartweather
it's a HACS integration with my weather station + dark sky forecast

ivory delta
#

Then you get an attribute from a sensor something like this: {{ state_attr('domain.entity', 'attribute_name') }}

#

In your case, you're probably interested in something like weather.home and condition.

zinc bloom
#

My problem is that there are multiple entries for the next 5 days, marked with a timestamp - datetime: '2020-06-14T00:00:00'

#

I need to pick the one for the next day, something like now().day +1 if that is possible at all

#

and match it to the datetime entry, then pick conditions from there...

ivory delta
#

That's not what you suggested in the snippet you posted...

#

If you want help, be clear about your requirements.

#

Show the real snippet please.

muted berry
#

So I'm trying to add this template to my configuration.yaml but it fails. I'm guessing I've screwed up something in the formatting

inner mesa
#

yeah, you can't do that

#

you want something more like this:

#
      #         {% if states('sensor.occupancy')|int > 10 %} green;
      #         {% else %} red;
      #         {% endif %}
muted berry
#

so what am I missing in my formatting?

#

I'm totally green on yaml formatting

inner mesa
#

you're using is_state() and trying to put a different test in the arugment

#

it's not a YAML formatting problem, it's a jinja issue

muted berry
#

so how would I properly write this? the script isn't mine

inner mesa
#

you also have nothing in the else clause, or an {% endif %}

#

it looks like you copied part of a broken template ๐Ÿ™‚

muted berry
#

It's actually the entire template that a friendly dude sent me

#

What I'm trying to achieve is having an automation read the temp of a specific template and once the temp hits a few key values, I want the fan speed of my hvac to change accordingly

inner mesa
#
          {% if states('sensor.temperature_5') < 25 %} 
            4
          {% elif states('sensor.temperature_5') < 24 %}
            3
          {% elif states('sensor.temperature_5') < 23 %} 
            2
          {% else %}
            something
          {% endif %}
#

see the difference?

muted berry
#

"Configuration invalid
Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['sensors']['flaktlageovervaning']['value_template']. Got "{% if states('sensor.temperature_5') < 25) %} 4 {% elif states('sensor.temperature_5') < 24) %} 3 {% elif states('sensor.temperature_5') < 23) %} 2 {% else %} 2 {% endif %}". (See ?, line ?). "

inner mesa
#

see the edit

#

and read through it so you understand it

muted berry
#

that's from pasting the edit in my config.yaml

inner mesa
#

no, it's not

#

look again

muted berry
#

I literally copy pasted what you wrote with the addition of changing something into "2".

inner mesa
#

do it again

muted berry
#

here's what's currently in my config.

inner mesa
#

I can see from your error that you don't have exactly what I have above

muted berry
#

holy..it works wtf?

inner mesa
#

that's the goal, right?

muted berry
#

I ment the config check

inner mesa
#

that, too

muted berry
#

Now I need to test the template ๐Ÿ˜„

inner mesa
#

now, read it and understand it. and how it's different from your first attempt

muted berry
#

so I assume that the action is call_service in the automation?

#

I sure will man..thanks a bunch!

inner mesa
#

depends on what you want to do with the sensor that you defined

muted berry
#

this - action:
- service: climate.set_fan_mode
data:
entity_id: climate.overvaningen
fan_mode: '{{ states.sensor.flaktlageovervaning.state }}'

#

basically call the template to compare current temp of the sensor to the template and set fan mode thereafter

inner mesa
#

that's overcomplicating things

muted berry
#

is it?

#

I've tried everything else by now without success

#

Heck..if you can help me solve this, you've got a beer on me

#

the hvac has four fan modes

#

3*

#

from 2-4

#

And I want the hvac to adjust the fan mode based on the temp of an aqara sensor

inner mesa
#

unless you're using that sensor somewhere else, it's weird to create a sensor for the template and then use the sensor value in the action

#

just put the template in the action

muted berry
#

Okay? so just straight as an action?

inner mesa
#

it'll work, but it's just kinda roundabout

muted berry
#

this is what I had earlier

#

that failed

inner mesa
#
action:
  - service: climate.set_fan_mode
    data_template:
      entity_id: climate.overvaningen
      fan_mode: >-
        {% if states('sensor.temperature_5') < 25) %} 
          4
        {% elif states('sensor.temperature_5') < 24) %}
          3
        {% elif states('sensor.temperature_5') < 23) %} 
          2
        {% else %}
          1
        {% endif %}
#

actually, that. action: isn't a list element

muted berry
inner mesa
#

make sense? did you have another reason for wanting the sensor?

muted berry
#

here's what I had earlier that failed

#

yeah, that does make sense..a lot more sense than defining a sensor for a single use

inner mesa
#

hey, that's better

muted berry
#

it is, but it fails

inner mesa
#

your indentation is wrong

muted berry
#

Why am I not surprised

inner mesa
#
        action:
          - data_template:
              entity_id: climate.huvudvaningen
              fan_mode: >-
                {% set temp1 = states('sensor.huvudplan_2')|float %}
                {% if temp1 < 22 %} 2
                {% elif temp1 < 23 %} 3
                {% elif temp1 < 24 %} 4
                {% else %} 2
                {% endif %}
            service: climate.set_fan_mode
#

service: climate.set_fan_mode should be 2 spaces to the left

muted berry
#

mind posting the entire thing in a hastebin? I'll 100% get it wrong lol

inner mesa
#

the spacing was even more messed up in hastebin, but looked better when I copied and pasted into VSCode

muted berry
inner mesa
#

uh, no

muted berry
#

the heck

#

see, this is why my stuff fails...the damn indentations lol

inner mesa
#

your action: block was way over to the right

#

trigger:, condition:, and action: need to be lined up

buoyant pine
#

- id: needs to move left two spaces (paste error maybe)

inner mesa
#

really, everything else needs to move 2 spaces to the right

muted berry
#

this is straight from the automations file. -id is as far left as it goes

inner mesa
#

here's a correctly formatted automation:

#
# turn off the fan after an hour
- id: Whole house fan turn off after time
  alias: Whole house fan turn off after time
  initial_state: true
  trigger:
    - platform: state
      entity_id: switch.whole_house_fan
      to: 'on'
      for:
        hours: 1
  condition: []
  action:
    - data:
        entity_id: switch.whole_house_fan
      service: switch.turn_off
muted berry
#

the ui really screws things over

inner mesa
#

it's still wrong

buoyant pine
#

Move service: climate.set_fan_mode left two spaces

inner mesa
#

yeah, I said that above

buoyant pine
#

And then the entire action over two spaces heh

muted berry
#

so four spaces on action?

#

the entire action

inner mesa
#

trigger:, condition:, and action: need to be lined up

#

just look my last hastebin

muted berry
#

right

#

so no space on - id and the rest follow the spacing

inner mesa
#

think of lining up blocks

#

better?

muted berry
#

Trying this

inner mesa
#

yeah, that won't work

muted berry
#

I cannot for the life of me get this damn formatting right

#

like...literally

inner mesa
#

just use exactly what I put above

#

exactly

muted berry
#

I did

inner mesa
#

and yet

muted berry
#

there's a ton of spaces in that pastebin

inner mesa
#

alright, I'll put everything to the left side

#

what editor are you using?

#

I encourage you to look into VSCode, which makes the indentation much easier

muted berry
#

YES!