#templates-archived

1 messages ยท Page 110 of 1

limpid anvil
#

I have an Xiaomi notebook pro with cracked screen! I could use that for doods

flat cave
#

I am "trying" to workout is there a way to template a notification that is "temperature was xc overnight" I have a simple automation that covers it was "below xc" , but would be nice to have an actual temp . IS this something a template can do even ?

arctic sorrel
flat cave
#

ahhh maybe ... will need to play .

But im guessing I will need a template to "read" the temp, and a template to make the notification

narrow sage
#

What am I doing wrong?

My template:

Distance: {{ states.sensor.zwift_online.attributes.latest_activity.distanceInMeters / 1000 | round(2) }} Km

Expected output:
Distance: 30.28 Km

Actual output:
Distance: 30.271900000000002 Km

buoyant pine
#

You're only rounding the 1000 to 2 decimal places

narrow sage
#

Yes... just realized. Parentheses help. OMG. Sorry.

#

And thanks!

buoyant pine
#

Lol it's all good

flat cave
#

https://www.home-assistant.io/integrations/history_stats/ could help
@arctic sorrel as its getting late i will have to play with it some more. but to check ..

entity_id: sensor.temperature_2
state: 'temperature' - is that right to be tracking the temp ?

#obvisuly correct time template i think
start: '{{ now().replace(hour=21, minute=0, second=0) }}'
end: '{{ now().replace(hour=06, minute=30, second=0) }}'

arctic sorrel
#

I'd check in #integrations-archived - I don't use it myself, just looks like the only thing that may be relevant here

dire flare
#

@dire flare Is the sensor you have in the ground bad? I feel like I would trust that over the weather ๐Ÿคฃ
@mighty ledge No it's actually pretty good! It's a miflora that I have polled using esphome

thorny snow
#

Are templates the only way to make icons change in lovelace? I've got some zwave door sensors that I've templated to open/close icon, but the other zigbee ones don't (obviously). Is this the only way to do it?

inner mesa
#

You may be able to change the device_class in customize.yaml

thorny snow
#

as far as I can tell, using the customization, I can only set the new icon, not one for open and one for closed... unless I"m missing how it works.

inner mesa
#

If you set the device class, it can set the icons accordingly

thorny snow
#

hmm, interesting, because I had to add this line to my binary sensor for it to showup on my zwave.
icon_template: "{{ 'mdi:door-open' if is_state('sensor.guest_room_door_access_control', '22') else 'mdi:door-closed' }}"

#

I guess, I could try to take that out and see if the device class is actually the part that makes that happen, i assumed it was that icon_template

inner mesa
#

Only if you donโ€™t like the ones it chooses with the device_class

thorny snow
#

ahhh

fossil hearth
#

@fossil hearth clear your cache and reload the page
@mighty ledge tried it did not work : /

fossil hearth
#

I just realized it had syntax errors too
@mighty ledge :0 is that why its not working ๐Ÿ˜› haha what should i do ? ๐Ÿ˜„

hollow rampart
#

I need some help figuring out how to configure a light domain into a cover domain using a template. I have a iblinds motor that is being identified as a light domain. Iโ€™ve been working on this template for three days and I just cannot figure it out.

amber zodiac
amber zodiac
deft timber
#

@hollow rampart, what do you have so far? you should be able to call the light.turn_on service as the open_cover attribute of your cover, light.turn_off as the close_cover... and potentially put smth like this in the template_value: : "{{ 'open' if is_state('light.my_cover', 'on') else 'closed' }}

distant plover
#

I have a markdown card in Lovelace showing a template of stuff from a sensor. The sensor is updated every 1800 seconds. What's the best way of showing 'last updated hh:mm:ss' in the card?

ivory delta
#

You'll want to use strftime to format the existing datetime into your preferred format. https://strftime.org/

distant plover
#

Hmm. I see from your URL that I can for instance do {{ as_local(states.sensor.thesensor.last_changed) }}. That gives me the time it was last changed. But what if I want it to show the last time it checked for change?

ivory delta
#

I don't think you can. You get information about the state of entities, not all the behind the scenes stuff that got it for you.

distant plover
#

So my only option then would be to add another attribute to the sensor with a timestamp?

ivory delta
#

How are you going to add attributes?

#

How do you know the value to add?

distant plover
#

I maintain the custom component. I was just thinking of grabbing sysdate or the equivalent in python code.

ivory delta
#

Then yes, feel free to add whatever attributes you want ๐Ÿคทโ€โ™‚๏ธ

analog plover
#

I have an entity called "sensor.shelly_shplg_s_0847af_current_consumption". This entity has an attribute called "ip_address". Can I write something in my lovelace card to display this property directly or do I need to define some template sensor that shows this specific attribute first?

#

I went so far as to write a dot after the sensor name followed by "ip_address", but that failed miserably.

ivory delta
#

It depends on the card...

analog plover
#

I have this entity card used for now, it displays some other properties from the entity but not the IP.

#

But you mean that I could "pull" this entity information directly into a card somehow? Without the need for creating a template sensor?

mighty ledge
#

@analog plover you can make a template sensor and pull the attribute from it. Otherwise you'd need to use a custom card to pull the attribute. Most built in cards only display the state.

distant plover
#

How does last_updated differ from last_changed, mono? When I was adding a last_update attribute to my sensor I suddenly saw the last_updated also existed.

mighty ledge
#

last_updated is the last time something updated the sensor, last_changed is the last time the state changed.

distant plover
#

So when I have a scan_interval at 1800 for my sensor, last_updated would change very 30 minutes? ๐Ÿ™‚

mighty ledge
#

yep

#

but last changed will only update if any state or attribute is updated

distant plover
#

Brilliant. Reverting all changes where I added a new attribute to sensor. ๐Ÿ˜„

#

Is this documented? My googling apparently sucks.

mighty ledge
#

yes

#

Hmm

#

I might have that wrong

#

Well, I do have it wrong. Read the fields in the state object, seems like both are a mix of what I described.

distant plover
#

Yes. Thanks.

#

Maybe I need my extra attribute after all ๐Ÿ™‚

#

Anyways. Annoying that a google search for 'home assistant last_updated' without quotes doesn't find that site but a bunch of community hits instead

#

Same with 'home assistant state.last_updated'

clever light
#

Not sure I should be posting in here, or one of the other rooms, so apologies if in the wrong place. I have a lamp with a remote that uses 433Mhz. Luckily I have openmqttgateway already set up with 433Mhz transmitters/receivers for some remote switches so I can see the button presses hitting the MQ. The remote is pretty basic - on/off, change temperature cycles through 3 settings, and brightness up/down buttons. What would be the best approach to create this as a light on Home Assistant. It doesn't have a brightness/temperature setting as you can imagine just the ability to step up/down. I'm thinking a combo of templating and an mqtt light but need a little point in the right direction to work it out.

thorny snow
#

Good evening everyone. I am trying to convert my received json temperature values reported in fahrenheit to Celsius with the template functionality. Anyone knows how to do this ? I found there is util helper for this but i am not sure if this can be used in templates. This is al new to me. Any hint or help would be greatly appreciated.

ivory delta
#

{{ (f - 32) * 5/9 }}, right?

#

Substitute f with your data source.

blazing burrow
#

I'd make it {{ ((f | float) - 32) * 5/9 }}, just in case the value of f isn't one already

#

I think that's right lol

#

or float(f)?

inner mesa
#

Thatโ€™s fine. Donโ€™t need the extra parens around it, though. Order of operations will make it work

mighty ledge
#

@inner mesa @ivory delta @thorny snow @blazing burrow You don't actually need a template for this guys. All you need to do is set the unit_of_measurement to ยบC and HA will do the rest.

#

as long as your systemwide units are set to imperial.

#

Its the only unit in HA that will be converted for you

silent barnBOT
hollow rampart
#

I need some help figuring out how to configure a light domain into a cover domain using a template. I have a iblinds motor that is being identified as a light domain. Iโ€™ve been working on this template for three days and I just cannot figure it out.

silent barnBOT
hollow rampart
#

Iโ€™m not getting any errors in configuration checker but I do get an error when I try to tilt Failed to call service ....extra key not allowed @ data

silent barnBOT
#

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

limpid anvil
#

I am trying to modify: {%- if otherPeople > 0 %} personen I want it to display persoon when the value is 1 and I want to display personen when te value is anything above 1. How can I do this?

hollow rampart
#

This has been solved btw thank you @deft timber. I will post solution in the forum.

ivory delta
#

What's the context, Tuxabyte? Is this part of a bigger template?

deft timber
#

{{ "persoon" if otherPeople == 1 else "personen"}} should work

rugged laurel
#

"person{{'en' if otherPeople == 1}}"

deft timber
#

not valid since there are 2 'o' if singular ๐Ÿ™‚ (persoon)

rugged laurel
#

It was not when I did it

#

That's cheating!

deft timber
#

loool, it was in the initial demand :-p

rugged laurel
#

TLDR ๐Ÿ˜›

limpid anvil
#

Thanks!

#

Yes, bigger template that outputs the number of detected people from doods (based on Tinkerer's config)

iron sparrow
#

Hello everybody,
need some help with the topic of templates. also in German, because my English is not the best :-)

Thanks and regards
Alex

stuck minnow
#

Hi, I'm looking to create a notify service to an arduino that accepts url queries to signify what color, duration and type of flash method for an led strip. I want to be able to swap out all the numbers with input_numbers in HA. I have a sample url of: [IP_ADDR]/notify?color=1671168&duration=5000&flash=10 What's the best way to construct this url and send the request?

clever fable
#

Does anyone know if it is possible to make a custom sensor that will count the number of hours of activity in a room via a motion sensor activation (it doesn't have to be super accurate) that would be resettable. My Idea is the track the amount of traffic in a room and then once it hits a particular threshold it would send out my Xiaomi Robot Vacuum to clean that particular room. (really it would turn on a binary sensor to set the vacuum to clean that room after everyone is gone for a particular amount of time, or possibly when they are all more than a particular distance from home.

dreamy sinew
#

hmm a few partial ideas but nothing great

ivory delta
#

First you'd have to determine what counts as activity. If you're only dealing with something like PIR motion sensors, it's going to be tricky to know for sure how long someone was in that room.

#

Assuming motion sensors, I'd probably go with dividing the day into time segments and counting how many segments had motion in them. Up to you how granular you want to get... and probably not solved with templates on their own.

#

Seems like an automation thing... every 5 minutes, check if there was activity in that room in the last 5 minutes, incrementing a counter if there was.

thorny snow
#

All you need to do is set the unit_of_measurement to ยบC and HA will do the rest.
@mighty ledge My sensor reads in Fahrenheit so i my unit_of_measurement is 'fahrenheit' I expect ? My system is set to metric but values ar

They are special-cased in the code
@inner mesa tried both values for unit_of_measurement but doesn't seem to do any conversion. Only the Icon label changes.

inner mesa
#

F and C, I believe

#

They are special-cased in the code

fallow scarab
#

I have a Shelly 2.5 that controls a shutter. I want to set up an automation that allows me to control it with "one" button: meaning, every time the button is pressed, the roller goes in the next sequence step (i.e. Open/Stop/Close/Stop/Open) Would I use templates for this? The shelly already shows up as a cover so i have cover.toggle, as well as open_cover, stop_cover, and close_cover. I guess I would need to retrieve the last step to know which step to perform next in the sequence ?

mighty ledge
#

@thorny snow set it to degree symbol f

#

And it will convert to c

thorny snow
#

@mighty ledge Tried all kind of symbols and letters. No luck. This is my code https://pastebin.com/mc65CaJh
This is the only working solution until now :

value_template: '{{ ((states.sensor.Garmon.attributes["tempf"] | float) - 32) * 5/9 }}'
coarse tiger
#

Line 4, tried unit_of_measurement: 'ยฐC' or unit_of_measurement: 'ยฐF'?

thorny snow
#

@coarse tiger 'ยฐF' works !! I was confused to use the degree symbol together with Fahrenheit. I was thinking it was only needed with Celcius.
I also noticed that unit_of_measurement line can/must be used in both sensor and template section in order to have conversion in both approaches.

mighty ledge
#

You donโ€™t need the template, only the unit_of_measurement

rugged lichen
#

Hello friends, I would like to create a template sensor where the value is only a number. The Value looks like that in the normal sensor:

388.76/453.51GB (85.72%)

the template sensor's value should be 85.72 or 85. doesnt matter which one. Can someone please help me? Thank you.

thorny snow
#

@mighty ledge My rest call receives multiple values like temperature, windspeed, humidity. They all need their own unit of measurement. Thats confusing to me how to handle without template.

mighty ledge
#

I feel like you didn't read my original message. You don't need to convert anything in a template when you have a temperature, only a temperature. All you need to do is output the value and use unit_of_measurement. Set unit_of_measurement to whatever unit the value is (NOT SENSOR), then the sensor will convert to your units set on the system. Again, this is only for temperature sensors.

#

So , in your case above, if your system wide units are set to metric then all you need is:

#
value_template: "{{ state_attr('sensor.Garmon', 'tempf') }}"
unit_of_measurement: ยบF
#

it will translate it to ยบC for you, without any need for conversion

thorny snow
#

@mighty ledge Thanks for explaining. I was indeed confused by thinking this was working for other imperial vs metric values I learned a lot.

deft timber
#

@rugged lichen : {{ your_sensor.split("(")[1].split(")")[0]}}

rugged lichen
#

@deft timber Thanks, can I check it in the template developer tools somehow? I tried this

{{ state_attr('sensor.radarr_disk_space' , '/') | split("(")[1].split(")")[0]}}
#

of course its not good ๐Ÿ˜„ Im sure im missing something.

deft timber
#

Yes indeed it is not ๐Ÿ™‚

mighty ledge
#

at least you tried!

#

@rugged lichen can you take a screenshot of the entity in devtools -> states page

#

or copy the results here

rugged lichen
#
/: 388.59/453.51GB (85.68%)
/data: 1460.82/1863.01GB (78.41%)
/config: 388.59/453.51GB (85.68%)
unit_of_measurement: GB
friendly_name: Radarr Disk Space
icon: 'mdi:harddisk'
#

I would like to use the attribute "/", what is showing the disk space usage of my first drive.

mighty ledge
#

oh god

#

whyyyy

rugged lichen
#

and I would like to see only 85.68 as the value.

deft timber
#

{{ states('sensor.radarr_disk_space').split("(")[1].split(")")[0]}}

#

(if the state of the sensor is the string you copied at the first place)

rugged lichen
#

@deft timber its in the attribute of "/"

deft timber
#

ok, try this then {{ state_attr('sensor.radarr_disk_space' , '/').split("(")[1].split(")")[0]}}

mighty ledge
#
{{ state_attr('sensor.radarr_disk_space' , '\/') | split("(")[1].split(")")[0] }}
#

it depends on how the attribute is presented

rugged lichen
#

@mighty ledge you just copy pasted back what I wrote ๐Ÿ˜„

mighty ledge
#

nope

#

check again

#

look at the attribute

rugged lichen
#

/ instead of /

mighty ledge
#

'\/'

rugged lichen
#

Yes

mighty ledge
#

\ escapes the character / to make sure it's passed properly as /

rugged lichen
#

TemplateSyntaxError: expected token 'end of print statement', got '['

deft timber
#

don't think ย | split will work. Use .split

#

as I wrote

rugged lichen
#

@deft timber Your idea was the solution. Thank you very much.

#

@mighty ledge Thanks for you too for your kindness!

#

now I just have to create the sensor.

#

Sorry but I have to ask for that too, thats the first time im doing template sensor and I cannot find the answer to that.

#

In normal case I would use value.split("(")[1].split(")")[0]

#

as a value_template in the sensor yaml.

#

but now I want the split of the state of the attribute.

#

how should I attach that to my config?

deft timber
#
sensor:
  - platform: template
    sensors:
      your_sensor:
        value_template: "{{ state_attr('sensor.radarr_disk_space' , '/').split('(')[1].split(')')[0]}}"
rugged lichen
#

Ah I understand, so I can use also the name of the sensor not just "value".

deft timber
#

yep

rugged lichen
#

Thanks, I learned a lot, I can start creating my ideas with this information!

rugged lichen
#

Thanks again @deft timber and @mighty ledge I was able to achieve this monitoring card with your help. Today's work was great :)
https://ibb.co/BfFj80f

deft timber
#

Glad I could help ๐Ÿ™‚

silent barnBOT
serene matrix
#

I just nicely formatted my code ๐Ÿ˜…

silent barnBOT
serene matrix
#

^ Second part of my message as I hit the character limit

silent barnBOT
#

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.

ivory delta
#

Nice. Over 60 lines of text. I'll pass.

inner mesa
#

When you "hit the character limit", best to consider whether you're sharing the most useful info

serene matrix
#

Alright, sounds reasonable. However, it just seems that the "Services" tab under Developer Tools is buggy. Calling the service in an automation with the exact same payload works.

https://hasteb.in/vovohoqi.yaml

#

But probably not for too long. Setting legacy_templates: false results in this error when running the automation: expected str for dictionary value @ data['media_content_id'] Reverting the setting plays an audiobook as desired.

Is this worth a GH issue or am I missing the obvious?

inner mesa
#

I don't know what to think about that. it evaluates properly in the template editor, so I would probably file an issue in Github

heady crow
#

Hi, I got a DIY garage controller with ultrasonic sensors angled at the cars, when a car is present, the sensor detects around 1m and shows in HA, if a car isnt present, the sensor says "unknown"
https://imgur.com/a/iogscHu
is it possible, with a template or other, to say the following

Sensor state = < 500mm or Unknown then report state = No
Sensorstate > 500mm then report state = Yes

waxen rune
#

@heady crow yes it is

#

I'd suggest a binary_sensor that shows true/false, on/off

#

For example: {{ states('sensor.your_sensor')|float > 500 }}

heady crow
#

ill have a look now, thank you @waxen rune

#
  - platform: template
    sensors:
      car_present:
        friendly_name: "Car Present"
        value_template: >-
          {{ states('sensor.garage_ultrasonic_sensor_left_2')|float > 500 }}
#

So i done the above @waxen rune how would i add the true/false to that, or that occurs by default???

#

So i done the above, State reports OFF even though the sensor reading is showing 1.06m, i noticed it was in metres too, and probably wont show mm, so i changed it to "float > 1" but that also does not work

#
  - platform: template
    sensors:
      car_present_r:
        friendly_name: "Car Present Right Side"
        value_template: >-
          {{ states('sensor.garage_ultrasonic_sensor_left_1')|float > 1.00 }}
deft timber
#

what shows states('sensor.garage_ultrasonic_sensor_left_1') and what shows {{ states('sensor.garage_ultrasonic_sensor_left_1')|float > 1.00 }} in the template testing screen ?

heady crow
#

i just restarted with 1.00 instead of just have 1

#

im getting a new state of "ON" which is great

#

so my min is now 1m to determine on

#

How would i now chang e the ON/OFF to a YES or NO

deft timber
#

if you wan't yes/no and not on/off, you have to use a sensor and not a binary_sensor

heady crow
#

oh ok

deft timber
#

and your template should look like {{ "YES" if states('sensor.garage_ultrasonic_sensor_left_1')|float > 1.00 else "NO"}}

heady crow
#

Thanks, Will try now ๐Ÿ™‚

#

That works, thanks heaps ๐Ÿ™‚

silent vapor
#

I don't know have already spent a lot of time but I really think this could be a bug?

#

Whatever i try,I cannot control the lock template (entity) from home assistant lovelace interface, the buttons just don't respond

north locust
#

hi guys i added 3 template sensors , but now log spits out errors cant figure it out ?

sick haven
#

Hello

sick haven
#

Did you know, if i can template localeโ€™s full weekday name in sensor?

#

Because, every test i do on model's dev tools, don't work...

silent vapor
#

I am investigating the following:

silent barnBOT
silent vapor
#

But this is not allowing the control via lovelace. i think this must be a bug...

sick haven
#

.state is it normal ?

#

line 4

silent vapor
#

what do you mean? is it normal?

#

oh sorry that. without .state it also not works

charred dagger
#

@keen sky value_template: "{{ states('sensor.zigbee_bathroom_humidity') - 10 }}"

silent vapor
#

Thus this also does not work:

silent barnBOT
keen sky
#

nope, give me error, that invalid key: "OrderedDict([("states('sensor.zigbee_bathroom_humidity') - 10", None)])"

charred dagger
#

Missed the quote. Sorry. I have updated my message

keen sky
#

unavailable

inner mesa
#

Needs |float

charred dagger
#

Always test run your templates in /developer-tools/template

silent vapor
#

If I control the lock via another way then it correclty reports the state (locked/unlocked) but I cannot control it

#

via lovelace and service

keen sky
#

TypeError: must be real number, not str

#

obviaslu it is read as string ?

#

value_template: "{{ "$%.1f"|format(states('sensor.zigbee_bathroom_humidity')) - 10 }}"

charred dagger
#

Yes, RobC is right, all states are strings. Try {{ (states('sensor.zigbee_bathroom_humidity') | float) - 10 }}

keen sky
#

yep !

#

it work !

#

thank you !

deft timber
#

@sick haven , {{ now().strftime('%A')}} works for me

true acorn
#

Hi.
I am trying to build a garage door template that is not straight forward. Anyone in here who might help?

sick haven
#

@sick haven , {{ now().strftime('%A')}} works for me
@deft timber hmmm, maybe it's because i have a debian with supervised ha ?

#

Because this don't work for me ๐Ÿ˜ฆ

deft timber
#

no, should work for every kind of installation. When you type that in the template testing tool, it doesn't work ?

sick haven
#

and it don't work

#

i have the full weekday name in english

deft timber
#

ah ok, it is a problem of language...

true acorn
#

Lets give it a go :)
I have a garage door that is controlled up or down with a puls switch. I also have sensor that knows the state of the door.
Is it possible to set up a value template for open and close command? So that when sensor reports closed, the close command does not work. And when open the open command does not work. Sort of making seperate open / close commands from just a impuls signal...

sick haven
#

ah ok, it is a problem of language...
@deft timber ho yes sorry

deft timber
#

my installation is in EN so for me, no problem ๐Ÿ™‚

sick haven
#

๐Ÿ˜„

#

obviously ๐Ÿ˜„

#

(maybe i don't know the difference between local datetime and the language)

deft timber
#

no no, I missunderstood

true acorn
#

yes. And done ๐Ÿ™‚

#

it is not just a mather of mapping

silent vapor
#

@true acorn That is exactly what I am here for also... I

true acorn
#

aha

silent vapor
#

but then I want it resented as a "lock"

#

presented

true acorn
#

so it is the syntax of the value template I dont know how to write...

#

I already has this up and running on a different sw. But since I am in the process of migrating to home assistant I need to get this one to work...

grand dust
#

After updating to 0.118 I am getting a template error. Been stuck on this one and can't seem to figure it out, hopefully someone can help (point out I am an idiot ๐Ÿ˜†

value_template: >-
        {{ ((float(states('sensor.routing_multilevel_sensor_air_temperature_5')) + float(states('sensor.routing_multilevel_sensor_air_temperature_3')) + float(states('sensor.routing_multilevel_sensor_air_temperature_2'))) / 3) | round(2) }}

In the logs I get:

2020-11-19 12:44:03 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('TypeError: unsupported operand type(s) for /: 'str' and 'int'') while processing template 'Template("{{ ((float(states('sensor.routing_multilevel_sensor_air_temperature_5')) + float(states('sensor.routing_multilevel_sensor_air_temperature_3')) + float(states('sensor.routing_multilevel_sensor_air_temperature_2'))) / 3) | round(2) }}")' for attribute '_state' in entity 'sensor.living_room_and_cinema_temperature'

From the error I get that "/" is not supported and that it has something to do with str and int but it makes no sense to me.

keen sky
#

one more question - value_template: "63.599999999999994" - how can i shrink to xx.xx

grand dust
#

one more question - value_template: "63.599999999999994" - how can i shrink to xx.xx
@keen sky Use the | round(2) option like in my example

mighty ledge
#

@grand dust verify that all entities exist.

#

Also, this is a perfect example for using | float over using float()

keen sky
#

cool !

#

๐Ÿ™‚

mighty ledge
#

float() will not convert the value if it fails to convert. | float will convert the value to the default float, which is zero. So you won't get an error but the template will still work

#

So during your update, one of those 3 entities no longer exists

grand dust
#

@mighty ledge They definitely exist and have values populated.

mighty ledge
#

You're getting an int/string division error

#

that means your items wrapped in float are not converting

grand dust
#

Ok so using | float might solve it?

mighty ledge
#

unsupported operand type(s) for /: 'str' and 'int''

#

Yes it will solve it but you'll just get 0/3

#

You should really look into why float is failing on those entities

grand dust
#

Thanks @mighty ledge at least I have something to go on

mighty ledge
#

personally, i'd change the template to make it easier to manage for testing.

{% set temps = [
  states('sensor.routing_multilevel_sensor_air_temperature_5') | float,
  states('sensor.routing_multilevel_sensor_air_temperature_3') | float,
  states('sensor.routing_multilevel_sensor_air_temperature_2') | float,
  ] %}
{{ (temps | sum / temps | count) | round(2) }}
#

then you can check what's in the list of temps in the template editor by doing

#
{{ temps }}
#

so you can see which ones are converting properly

grand dust
#

That is so much neater and easier to read!

mighty ledge
#

also, it makes it easier to add temperatures at a later day

grand dust
#

Legend!

#

Using your version the error is gone and the temp is showing correctly ๐Ÿ™‚

mighty ledge
#

nice!

#

wondering what the problem was

grand dust
#

Not sure, it worked fine for a long time (since I think 0.44) and only started to give me an error with 0.118

mighty ledge
#

there was a change in how templates output

#

still doesn't make sense how you were getting a str / int division error if everything was converting properly

#

maybe there was a change to float()

waxen rune
#

I got curious, and for me those two works fine and give the same result:

{{ ((states('sensor.kok_temperature') | float + states('sensor.inplastad_temperature') | float + states('sensor.lackagesensor_temperature') | float / 3 )) | round(2) }}
and
{{ ((float(states('sensor.kok_temperature')) + float(states('sensor.inplastad_temperature')) + float(states('sensor.lackagesensor_temperature')) / 3 )) | round(2) }}

#

so maybe the thing about not converting a missing value?

#

Another thing, since 0.118, my template
{{ (states('sensor.utomhus_framsida_temperature') | round (1))}}
doesn't show any decimals when the value is exact anymore.
So 1.33 shows as 1.3 as expected, but 1 shows as 1, instead of 1.0as it used to.

Just verified that 0.116.4 show decimals for integers with the same template. I can't find anything in the release notes about that.
Issue or by design?

dreamy sinew
#

ints don't have decimals as a rule

waxen rune
#

bad wording

dreamy sinew
#

but that's semantics

#

yeah, was being a dick

waxen rune
#

it's not an integer, a float without decimals

dreamy sinew
#

+1

waxen rune
#

but the issue (?) remains

dreamy sinew
#

might want to just use the min_max sensor for these though

waxen rune
#

I never saw this while in beta. Maybe the temperature just never happende to be exactly 1 degree

dreamy sinew
#

otherwise you get weirdness when one of them is unknown because that'll |float to 0

silent barnBOT
waxen rune
#

Yep, I might. But should I raise an issue? As far as I can tell it is an undocumented changed behavior. But maybe I'm just a sloppy reader..

charred dagger
#

{{ "%0.1f" | format(states('sensor.utomhus_framsida_temperatur') | round(1)) }}

waxen rune
#

TypeError: must be real number, not str

#

Now the temperature increased to 1.1 so .. problem solved ๐Ÿ™‚

charred dagger
#

{{ "%0.1f" | format(states('sensor.utomhus_framsida_temperatur') |ย float | round(1)) }} then

waxen rune
#

yep, just saw that

mighty ledge
#

I think the main issue is that you were missing float

#

states('xxx.xxx') is always a string

waxen rune
#

well.. no. or yes :-)
the main thing is that it has changes since 0.116.4

mighty ledge
#

I don't know how round worked at all on the string prior to the current version, consider yourself lucky

waxen rune
#

I can absolutely change the template, no problem. but it works differently than before

#

I'll do a CTRL+H and just update the template sensors. Still confused why it happened though.

mighty ledge
#

there should be nothing to be confused about

#

you literally got lucky that the template worked before

#

it just so happens that it now errors because of changes

waxen rune
#

that's fine. I'm just looking for the reason so it can be documented

#

If it happens to me, it will probably happen to others

mighty ledge
#

So, what's the value of states('sensor.utomhus_framsida_temperatur')?

#

if it's a whole number, it will truncate the .x because it's not a number its a string

#

whole number meaning '1.0'

waxen rune
#

that one changes so often, so let's take this instad: {{ state_attr('weather.home', 'humidity') | round (1) }}

#

in 0.116.4, it shows 68.0

mighty ledge
#

'1.0' | round(1) returns 1

#

'1.1' | round(1) returns 1.1

#

all because it's a string

waxen rune
#

but the state is 68

mighty ledge
#

is it 68.0?

#

or flat 68?

waxen rune
#

no, it's 68

#

flat

mighty ledge
#

ok, then your result will be 68

waxen rune
#

now, yes. in 0.116.4, no

mighty ledge
#

that's great, its still wrong syntax

#

But, it looks like a bug in round

waxen rune
#

I don't argue with that. I know you are king of templates. But something has changed. that's fine. I'd like to document what

#

but it's no biggie.

mighty ledge
#

Ok, so it seems like this is a result of the typing changes

#

it is a bug

#

Also, they added conversion of for users inside the round function. float is not needed

waxen rune
#

ah, ok.

#

I'll leave it here. I just noticed the difference. If an issue should be raised, I'd appreciate if one of you who actually know what you're talking about do it ๐Ÿ™‚

mighty ledge
keen sky
#

hello, when I try this in dev tools : "{{ "%.1f" |format(states('sensor.zigbee_bathroom_humidity')|float - 10 ) }}" it work fine. but when i put in my .yaml file give me error: found character '%' that cannot start any token. How to fix that ?

mighty ledge
#

@charred dagger even formatting fails {{ "%0.1f" | format('1.0' | round(1)) }} does not work. It's a bug, put a PR above.

dreamy sinew
#

you're chopping your template with your quotes

deft timber
#

@keen sky : "{{ '%.1f' |format(states('sensor.zigbee_bathroom_humidity')|float - 10 ) }}"

#

if you put double quotes around your template, use single quotes in it

keen sky
#

@deft timber thank you! i just start to learn jinja .. but is hard for me still

#

works

silent vapor
#

Hi is there anyone able to help met with a "template" problem? I have trief with a lock template... had some result but not stable. Now switched to cover template (nicer for my gate) bt I seem to have the same unreliability problems...

#

The problem I am trying to solve is very simple. i have a gate that opens and closes with a pulse (is now a switch entity in home assistant)

#

pulse ~1-2 sec: open, pulse ~1-2 sec: close

#

and a door sensor (on/off) connected to the gate (to see the state)...

inner mesa
#

that thread seems to indicate that you think you solved it

exotic arch
#

Hi all

#

Can I post a snip of a tiny problem that needs fix'n ?

silent barnBOT
#

@exotic arch 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?
exotic arch
#

Hi all, I made a value template to change a switch value from on/off to open/closed. Problem is that I now see a ' after the value in lovelace...open' or close'. How do I remove this - ' -

torpid mason
#

Hello, Can i access an attribute of a sensor (temperature of climate integration) without having to use a template sensor some how?

silent barnBOT
barren rose
brisk temple
#

@torpid mason most likely

#

{{ state_attr('climate.name', 'temperature') }}

deft timber
#

@exotic arch, could you share your template?

torpid mason
#

@brisk temple cool thanks

silent barnBOT
deft timber
#

Well it is because you have an extra quote in your template ๐Ÿ™‚

exotic arch
#

@deft timber thanks for helping out ๐Ÿ™‚

deft timber
#

After the endif

#

{% endif %}'

exotic arch
#

@deft timber Shi* you are right! thx buddy...drove me crazy!!

brisk temple
#

@barren rose i'm not sure what your trying to do

deft timber
#

didnโ€™t really understand neither ๐Ÿ™‚ but I think you have an indentation problem. data_template should be aligned with service

#

And the fact that you are building a time like this : 00:00:00:00 is strange to me, the :00 at the end shouldnโ€™t be there.

proud hull
#

Hello everyone!
I am trying to get the current energy meter tariff.
I tried with the following but I'm not sure it's working as intended:
{{ย is_state('utility_meter.generale_consumo_giornaliero', 'F1') }}
There's some other attribute I should use instead to get the current tariff?

ivory delta
#

The tariff is an attribute of a utility_meter, right? Not the state itself.

proud hull
#

@ivory delta I think the same, but I can't find the correct attribute

ivory delta
#

What do you see when you search for that entity at devtools > States?

#

It will show you the state and all available attributes.

proud hull
#

I see:
state: F1
state attributes:

  - F1
  - F2
friendly_name: generale_consumo_giornaliero
icon: 'mdi:clock-outline'```
ivory delta
#

Ok, so the state is what you want to check ๐Ÿ™‚ What does the template you shared show in devtools > Templates?

proud hull
#

It outputs True

ivory delta
#

But you want the tariff name?

#

{{ state('utility_meter.generale_consumo_giornaliero') }}

proud hull
#

No, I wanted the true/false state... Give me a second and I'll explain (I'm italian and I'm a bit slow writing english)

#

The template works... So the problem is that I don't know how to set the tariff manually...!

#

How can I call the change tariff service manually?

#

(I just started to play around with the automations, please excuse me if my questions are way too obvious...!)

ivory delta
#

utility_meter.select_tariff sounds like what you're after. You'd call it from a script/automation or even from a #frontend-archived button action.

proud hull
#

Great! I'll use the frontend button (I have some automations in place that call select_tariff but I'm debugging them, that's why I need to change the tariff manually)

#

Thank you very much!!!

proud hull
#

@ivory delta I used a button to change tariff manually, and I've also found the issue with my automations (the name of the tariff was uppercase but in the automation was written lowercase......). You really helped me a lot, your suggestions really helped me solve the issue a lot quicker... And since it's midnight here I appreciate even more your help!!!

ivory delta
#

No problem, glad to help.

blazing burrow
#

umm, about to update to 0.118... any type of templates I should be particularly concerned with not carrying over correctly?

desert crane
#

plez advise, why trying to reverse a switch in configuration.yaml doesnt seem to have effect. sonoff controls radiator valve. it's normally open so "on" relay means "off" radiator so I need to reverse it for generic thermostat.
https://paste.ubuntu.com/p/Q3c3NY3nC5/
shouldnt that do the trick? or this template gets ignored by
climate:

  • platform: generic_thermostat
    that comes later?
plush cave
#

Hey all, I'm trying to write an automation that turns off my christmas lights every morning at 9am but I'd like to put a condition to NOT turn them off Christmas day. Mono suggested in automations channel that it could be a condition using a template saying something like 'month is 12 and date is not 25' ? Need some help with that since I've never used templates if someone can help. Here's my current automation https://paste.ubuntu.com/p/dqbDBvygtf/

ivory delta
#

It'd be something like this: {{ now().month == 12 and now().day !=25 }}

#

You can test it in devtools > Templates and tweak the numbers to see if it works.

plush cave
#

oh nice, thanks!

inner mesa
#

That will also restrict it to December

plush cave
#

is this how I would add it to the yaml (I'm sure i'm probably wrong)? I'm having a hard time understanding the syntax after reading through the docs

  • condition: and
    conditions:
    • condition: date
      type: template
      data: {{ now().month == 12 and now().day !=25 }}
#

nevermind, i think i'm doing it right through the gui

#

@inner mesa when you say it will restrict it to December, do you mean that the automation will still run in November? and it will ONLY not run on 12/25? Hopefully thats what you mean because that's the behavior I'm hoping for

open belfry
#

Does anyone have an example of how to use code_template to define more than one code for the manual alarm control panel?

I don't understand what the formatting should look like from the documentation.

plush cave
#

so, been trying different things because i'd like this to run in Nov,Dec, and Jan but NOT run on Dec 25. Tried this with the template editor but it's not giving me the right value, says true for everything. {{ now().month == 11 or now().month == 12 or now().month == 1 and now().day
!=19 }} <-- I was hoping it'd say false since today IS the 19th

inner mesa
#

not (month == 12 and day == 25)

plush cave
#

oh thanks, much simpler to getting this to work ๐Ÿ™‚ {{ ( now().month == 11 or now().month == 12 or now().month == 1 ) and now().day
!=25 }}

sleek tinsel
#

So I can't figure out why my sensor icon isn't changing. It stays as the eye, everything else works.

#
sensor:
  - platform: template
    sensors:
      wind_direction:
        friendly_name: 'Wind direction'
        icon_template: >
            {{'mdi-compass'}}
        value_template: >
            //removed for brevity//
thorny snow
#

hello everyone!

#

I've got a problem with a template sensor. Its template is built taking into consideration the value of other two sensors. When I paste the template into developer tools, it works out nicely. However, when I check the state of given sensor in Developer tools, it shows "unknown". Any ideas?

thorny snow
#

it's not an identation problem or anything of the sort, the sensor has been working great until yesterday, and I didn't change anything

waxen rune
#

@thorny snow Mind to share? Probably easier to help then. And what happened yesterday? Upgraded?

thorny snow
#

yep gimme a second

#

what happens is, this template, I use the exact same one for 4 or 5 sensors

#

it's been working great for the other 4 sensors.. now with this one,it's doing this strange behaviour... A couple of days ago it behaved the same way. Worked nicely under developer toolstemplate, but shower "Unknown" states.. I managed to get it working by moving the code a few lines below in configuration.yaml.. I copied it and moved it and it began to work.. now it's back to doing that

#

should I use pastebin?

#

pastein ain't working, so..

silent barnBOT
thorny snow
#

see, the same just happened, I went to configuration.yaml, moved it a few lines down, and it's working again...

#

all involved sensor are being updated every 5 minutes..

deft timber
#

@desert crane I donโ€™t see any reason why it should not work

waxen rune
#

any error in log?

#

does it work when sensor.nadal_playing actually is playing?

#

I tried the code but replaced the sensor. it works when the first if is true, otherwise I get TypeError: unsupported operand type(s) for -: 'NoneType' and 'float' in dev tools

thorny snow
#

I'll check for error, I just restart and the log cleared out..

#

but isn't it rare that it works in developer tools?

#

and ends up broken out from there?

waxen rune
#

did you check my question above? that would indicate there is an error in the else part.

thorny snow
#

I just restart HA and all error have been removed if there was any

#

no errors atm

waxen rune
#

what happens if you just cut out the first if? here it doesn't evaluate in dev tool then

#

Well, I would start there. I hope you find it!

thorny snow
#

yup, I believe I'll do the sensor in some other way...

#

I'll check for errors

#

thanks

#

I cut the first if and it's still working

waxen rune
#

I should work, but now you got me curious again. Now it works, but it stops working .. when?

thorny snow
#

not sure when.. I just made it yesterday..

waxen rune
#

After Y time or Y state changes or ..?

thorny snow
#

what I know is that if I delete it, restart HA, repaste it, restart HA, works again

waxen rune
#

ok

thorny snow
#

first time it stopped

#

I didn't even delete, I just copied it from YAML and moved it like 50 lines below, and it suddenly worked :S

waxen rune
#

and now when it works, does it work no matter the sensor.nadal_playing and sensor.nadal_utc states?

#

since those are the only variables (except for time)

thorny snow
#

I made it yesterday and as of now I can confirm it has worked with two different values of each of those sensors

#

btw, I'm updating all sensors involved every 5 minutes with homeassistant.update_entity

waxen rune
#

you could manually change the states of sensor.nadal_playing in dev tools to begin with

#

just to provoke

thorny snow
#

I dunno how to do that?

#

how?

waxen rune
#

Dev Tools > States

thorny snow
#

I see the blue button, yep

waxen rune
#

cklick the entity sensor.nadal_playing , change the state to (whatever) in the field State on top

#

Click Set State

#

it won't change the actual state (nothing will start or stop playing), but it will change the state = test the template

thorny snow
#

yep, I moved it back and forward among the two posible states and it's working..

waxen rune
#

if you try a state that should never appear?

#

like asdasd

thorny snow
#

I guess it'll work since only playing state matters

#

gimme 1 sec

waxen rune
#

just ruling out the unexpected

thorny snow
#

yep, works.. triggers the automation

#

I understand, it feels so silly, one has to try silly things

waxen rune
#

If we can't provoke it to produce an error, I guess you need to keep an eye on it and check the logs as soon as it appears again

thorny snow
#

that I will do... if it gets too silly, I'll just built the sensor in some other way I believe.. what's weird is that that very same template, I use it with other 4 sensors and they have showed no problems at all :S

#

thanks for your time!

waxen rune
#

just one question, does this need to be float ?
as_timestamp(now())|float)

#

when I provoked it, I got a operand type(s) for -: 'NoneType' and 'float' which would indicate a relation. A stretch maybe, but since we don't find anything else..

thorny snow
#

I'll start from there then, I believe it needn't be a float

waxen rune
#

or the other way around, if that one does - maybe states('sensor.nadal_utc') also should?

#

again, swimming in deep water now ๐Ÿ™‚

#

good luck!

thorny snow
#

hehe

#

I appreciate your time

#

I'll start from there..

#

wish me luck I'm not back here with this issue ๐Ÿ™‚

#

have a good day

waxen rune
#

same to you. and please report back if you solve it. always good to know what it was

limpid anvil
#

I have camera screenshots saved with date & time config/www/(voordeur_{{ now().strftime("%Y%m%d-%H%M") }}.jpg). How can I make home assistant display the latest local image file in lovelace ?

waxen rune
#

I think the easiest is to make two copies of the screenshot, one with the current name, and one with a static that always in overwritten. then you won't even need a template in lovelace.

limpid anvil
#

Thank you, haven't thought of that

desert crane
#

To make a new reversed dummy switch, i should not use the same entity name down below? How is new entity defined, can i just write whatever into there and due to being defined there, an entity is made?
https://paste.ubuntu.com/p/Q3c3NY3nC5/

deft timber
#

an entity switch_state_revert will be create in your case, that's the name you gave it

#

switch.switch_state_revert

desert crane
#

oh thats the entity name.. doh, right. Thanks

#

thats where i was failing at ๐Ÿ˜› @ivory delta

#

my noob thinking was, that my original switch gets reversed, after sleeping i thought about defining new entity, and i was already doing it as i now found out

distant plover
north locust
#

hi guys anyone have an alternative to speedtest.net integration ? mine is giving inaccurate results, nowhere near my real speeds i have 300mbit/300mbit sensor.speedtest only outputting 80/90 (yes its on an 1gbit network card)

ivory delta
#

What device are you running it on?

north locust
#

Corelec machine Arm based

#

which has a 1gbit nic

#

when i run speedtest in browser it gives normal results

#

maybe to do with running HA as a docker container ?

ivory delta
#

I don't know much about Docker but I don't think it would limit the bandwidth like that.

#

You used the browser on the same machine?

north locust
#

nope my home pc

ivory delta
#

So they're not comparable...

north locust
#

your right

ivory delta
#

You need to consider all of the infrastructure between HA and the internet. Even bad wiring from that device means it won't get 1Gbps

#

My HA host has crappy wiring but I don't care about it getting maximum bandwidth. It just means that running Speedtest from HA gives inaccurate results ๐Ÿคทโ€โ™‚๏ธ

north locust
#

a sorry

#

will try running speedtest on that machine in browser

#

see the results

sleek tinsel
#

@sleek tinsel You probably copied it from https://materialdesignicons.com/? Replace the dash, try {{'mdi:compass'}} .
@waxen rune

Yup that's what it was, thanks!

#

Btw, is there a faster site that indexes MDI icons?

thorny snow
#

@waxen rune hey, I realized.. that sensor I showed you before depends on another 2 sensors. Those two sensors are scrape sensors, might that have anything to do with the issue? however, when I check the state of those scrape sensors in developer tools, they both show a state

waxen rune
#

as long as those always have the predicted states you should be fine. might need some error handling if they scrape up something unexpected though

trim geode
#

is it possible to template a entity picture on something other then a sensor?

#

changing a persons entity picture based on if there home or away, or change a entity picture of a blind when it's open or closed.

trim geode
#

found a way using custom_ui

blissful mirage
#

Before v0.118 I was able to write json STRINGS to a file for later retrieval. Now these same templates look like type 'dict' which cannot be written directly. So my question is, how do I convert a 'dict' to a string so it can be written to a notify file, and read back in as a sensor?

ivory delta
#

What does your template look like now?

blissful mirage
#

{"Nov":[{"d":15,"$":2.62},{"d":16,"$":2.56},{"d":17,"$":2.51},{"d":18,"$":2.24},{"d":19,"$":2.25}]}

#

I've been writing lines like that to a file and was able to read them back in without issue. I can still read them back in but I can no longer write them using notify.file

ivory delta
#

The template, not the output

blissful mirage
#

the template i pasted in above was the last line I was able to successfully write to the notify file. ...

ivory delta
#

That's not a template. That's a string.

#

What template creates that string?

blissful mirage
#

sorry ... yes its a string ... that string comes from this template: "{{ state_attr('sensor.household_energy_cost_tracker','bill_cycle_json') }}"

#

and that attribute is a JSON dict

ivory delta
#

Try just adding | to_json to the end to force it into JSON (which is a string representation of an object, rather than the object itself):
{{ state_attr('sensor.household_energy_cost_tracker','bill_cycle_json') | to_json }}

#

When you load it, you may need to do the opposite (| from_json)

blissful mirage
#

are you sure I can write that to a notify file? ?

#

I'll give it a shot and let you know. it seems like notify file will only write strings... unless the 'to_json' filter converts it to a string

ivory delta
#

That's what I just said. | to_json makes it a string.

#

Dicts aren't JSON. Dicts are objects in memory. JSON is a string representation.

#

If you want to make something portable (HTTP/logs/text/etc), you use JSON.

blissful mirage
#

I see. got it. thanks so much for your help ... I'll give it a shot

mighty ledge
#

@blissful mirage I'd wager that it's a bug due to the template changes

blissful mirage
#

yep...

mighty ledge
#

I would assume there is no work around and you should report it

ivory delta
#

Isn't the workaround what I suggested?

#

It won't implicitly return a string now, gotta force it.

mighty ledge
#

I doubt it will work because the parsing happens after the fact

#

but it's worth a shot

ivory delta
#

Well TGG's all set to test it ๐Ÿ™‚

blissful mirage
#

I'll give it a shot, but i did try doing just that before coming here in the developer tools/templates and it just converted it back

#

I'll let you guys know regardless... thanks for the help. Never used Discord before

ivory delta
#

If it converts back when you do it to your log file, definitely report it.

blissful mirage
#

will do... now stupid question. where do I report it?

silent barnBOT
ivory delta
#

I think this'll be core since that's where it's evaluating the template.

blissful mirage
#

thanks

#

no joy. same error:

#

2020-11-20 17:32:43 ERROR (MainThread) [homeassistant.components.automation.home_assistant_shutdown] Home Assistant Shutdown: Error executing script. Invalid data for call_service at pos 2: template value should be a string for dictionary value @ data['message']

ivory delta
#

Ah, definitely a bug then ๐Ÿ˜ฆ

blissful mirage
#

ok. thanks again. you guys have been great

ivory delta
#

No problem. ๐Ÿ‘Œ

blissful mirage
torn meteor
#

is there an explode(",") or split(",") function in jinja? can't find one...

#

i know there's a join(), so why isn't there an opposite?

blissful mirage
#

The air quaility is {{ states('sensor.waqi_friendly_detail').split(' ')[0].upper() }}

deft timber
#

@torn meteor there is a split yes ๐Ÿ™‚

#

โ€œ{{ 'a,b,c' | split(',') }}โ€

torn meteor
#

ok

#

.split() works

deft timber
#

yes indeed sorry, | split() does not, @blissful mirage was right ๐Ÿ™‚

torn meteor
#

thanks

#

also, i'm trying to set my template sensor unit of measurement to a template value

#

but... it doesn't like it

open belfry
#

Hey guys, does anyone have ANY example of using code_template for the Manual Alarm Panel? I would like to have more than just one code to disarm my Konnected.io system, but I'm just not understanding what the formatting should look like.

inner mesa
#

As far as I can tell, itโ€™s just a way to dynamically assign the code to use

torn meteor
#
  - platform: template
    sensors: 
      baby_sleep:
        value_template: |
          {{ relative_time(states.input_boolean.baby_bedtime.last_changed).split()|first|int }}
        friendly_name: 'Baby Sleep' 
        unit_of_measurement: |
          {{ relative_time(states.input_boolean.baby_bedtime.last_changed).split()|last }} # NOT WORKING
open belfry
#

@inner mesa Oh ok. So no way to give each person in my house a different code really. At least from that example, you can only assign a different code for each possible alarm status.

torn meteor
#

i'm basically trying to have the unit be whatever the relative_time function decides - it could be "seconds" or "minutes" or "hours"

inner mesa
#

The backend doesnโ€™t know whoโ€™s logged in, so I donโ€™t think thatโ€™s possible

open belfry
#

Thanks! I can live with one code. Much better than the old piece of junk alarm system that was in this place when I bought it.

deft timber
#

@torn meteor, not sure you can use a template for the unit_of_measurement

dreamy sinew
#

@torn meteor i don't think that field supports templates

#

oh

#

lol

deft timber
#

๐Ÿ˜›

#

it should be a string, see the doc

torn meteor
#

dangit. can we make that dynamic? would you think that's a good idea?

#

(to open a PR)

deft timber
#

from my point of view, everything should be usable with a template ๐Ÿ˜€

dreamy sinew
#

eh stuff like that is harder

north acorn
#

can someone explain to me how to use template inside an array? for instance:

parameters:
  - play
  -         {% if is_state("input_select.slaap_scene_speaker", "Woonkamer") %} media_player.woonkamer_lms_original
            {% elif is_state("input_select.slaap_scene_speaker", "Kantoor") %} media_player.kantoor_lms
            {% elif is_state("input_select.slaap_scene_speaker", "Slaapkamer") %} media_player.slaapkamer_lms
            {% elif is_state("input_select.slaap_scene_speaker", "Woonkamer & Slaapkamer") %} media_player.woonkamer_slaapkamer_lms
            {% endif %}
#

I need that template block to be the 2nd option of the array

#

but I can't figure out how to make that work

#

copying/pasting breaks the script

#

the template by itself does work (for instance when using only parameter: > and then template on the line below it

ivory delta
#

Pretty sure you can't do that. You need your template to output the desired array, not just part of one.

north acorn
#

Hmm so itโ€™s impossible to template a service call where one of the elements is a list?

#

The parameter has 2 variables in the list: 1 is play and the other is entity_id

#

So I would need a template that outputs play and entity_id?

#

Sorry, itโ€™s not entity_id but a spotify/tidal link (doesnโ€™t matter in this context though)

dreamy sinew
#

if you're on 118 you could try:

parameters: >-
  {%- set map = {
    "Woonkamer": "media_player.woonkamer_lms_original",
    "Kantoor": "media_player.kantoor_lms",
    "Slaapkamer": "media_player.slaapkamer_lms",
    "Woonkamer & Slaapkamer": "media_player.woonkamer_slaapkamer_lms"
  } -%}
  {{ ["play", map[states("input_select.slaap_scene_speaker")]] }}```
distant plover
cold hazel
#

hi, could someone help me with read value from mqtt_sensor? I have value like this: 21.88;65185;ok ยฐC. How I can read only "21,88" ?

brisk temple
#
{% set data = '21.88;65185;ok ยฐC' %}
{{ data.split(';')[0] }}
#

@cold hazel try that second line

cold hazel
#

๐Ÿ˜—

#

works thank you

mellow knot
#

hello guys. how can i use sun elevation angle as a value for light brightness. Here is what i have and trying to figure out how to set value with sun elevation change. https://paste.ubuntu.com/p/rQHSmCptZS/

inner mesa
mellow knot
#

the second part is where im stuck. can i get an attribute value (sensor.elevation) and pass it on to brightness_pct (im sure after running it through a numeric filter to get whole numbers etc).

inner mesa
#

yes, you can reference the elevation in a template, which you can pass to the light.turn_on service in the data: section

#

you don't even need to use a trigger variable for that, just the current elevation attribute

mellow knot
#

as such
action:

  • service: light.turn_on
    data:
    brightness_pct: 10
    entity_id: light.blue_spectrum_brightness
    mode: single

how to reference the elevation attrubute to substitute the hard value i.e. "10" in above paste

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

Don't forget you can edit your post rather than repeatedly posting the same thing.

For over 15 lines you must use a code share site such as https://paste.ubuntu.com/ or https://www.hastebin.com/.

inner mesa
#

you use a template

silent barnBOT
inner mesa
#

you'll need to decide how to convert the sun's elevation to a brightness_pct based on whatever formula you wish

#

but this will return the sun's current elevation: {{ state_attr('sun.sun', 'elevation')|float }}

#

this is certainly wrong, but you could use it directly like this:

mellow knot
#

i beleive if can divide this by 2.55 as such {{ state_attr('sun.sun', 'elevation')/2.55 | float }}

inner mesa
#
data:
  brightness_pct: "{{ 10 if state_attr('sun.sun', 'elevation')|float < 5.0 else 20 }}"
#

{{ state_attr('sun.sun', 'elevation') | float / 2.55 }}

#

but, yes

#

you can test the formula in devtools -> Templates

mellow knot
#

so once i save this automation and i went ahead removed the trigger part. it sets brightness_pct to null.

#

brightness_pct: null

inner mesa
#

did you test it?

#

I believe you need to edit the YAML directly to use templates in the UI

mellow knot
#

i see

#

this maybe not allowed in UI

#

that makes sense

#

i know its formatted correctly. it still marking it with error.
missed comma between flow collection entries at line 460, column 59:
... tate_attr('sun.sun', 'elevation') | float / 2.55}}

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

Don't forget you can edit your post rather than repeatedly posting the same thing.

For over 15 lines you must use a code share site such as https://paste.ubuntu.com/ or https://www.hastebin.com/.

inner mesa
#

you missed the quotes

#

I also recommend indenting entity_id: by 2 spaces, but it may not be necessary there

mellow knot
#

RobC thank you so much for the help so far. i cant believe after all this its still not working. i even added a trigger just to see if elevation change would do anything but still at the same place. here is my automation so far. https://paste.ubuntu.com/p/hvYPDj6RZn/

inner mesa
#

do you want to use the state of sensor.elevation in brightness_pct?

mellow knot
#

its really the same as sun.sun elevation but i wanted to try it any way.

inner mesa
#

what isn't working?

mellow knot
#

its not setting my light brightness. so basically elevation (sensor.elevation and sun.sun elevation) are 35%

inner mesa
#

and what does the next_change attribute represent for sensor.elevation?

mellow knot
#

i figured if multiply by 4 i get around 56 and thats what i was hoping the light brightness would set to

inner mesa
#

where does that sensor come from?

mellow knot
#

sensor.elevation is coming from sun2 component

ivory delta
#

Multiplying negative numbers by 4 still ends up with a negative number, btw ๐Ÿ˜‰

#

You don't want to use elevation directly.

mellow knot
#

yah that was part of a test value.

#

true

ivory delta
#

You said you want it to emulate the real brightness, right?

mellow knot
#

i will probably set a condition on elevation as such if above 0

#

yes

ivory delta
#

No light after dark? Brightest at noon?

mellow knot
#

yes

ivory delta
#

Then you almost have the right idea. You just need to ignore negative values. And it'll still be a pretty rudimentary solution compared to just using flux.

mellow knot
#

for some reason flux didnt work for me and then i attempted to use circadian lighting which implements around the same way. both no go.

#

i am able to change brightness for the same lights manually. np

ivory delta
#

Try something like this...
{{ ([states('sensor.elevation'), 0]|max) * 4 }}

mellow knot
#

should i go ahead remove trigger then or keep it the same.

ivory delta
#

Should never go negative, since you're always picking the larger value of the two in the list. Tweak your scaling factor to suit your needs.

#

You still need a trigger ๐Ÿ˜‰

mellow knot
#

current sensor.elevation next_change is ok for this scenario?

ivory delta
#

I'd skip the attribute though. If all you define is the entity_id, it'll trigger whenever any property of that entity changes.

#

State and attributes.

#

Slight adjustment since it complains if you don't cast to a float:
{{ ([states('sensor.elevation')|float, 0]|max) * 4 }}

mellow knot
#

saved and testing this now

ivory delta
#

I just tested with these. First one first -26ยบ and second gives 0:

{{ state_attr('sun.sun', 'elevation') }}
{{ ([state_attr('sun.sun', 'elevation')|float, 0]|max) * 4 }}```
#

Stupid bot.

real raven
ivory delta
#

Yep, looked at it. You're welcome.

real raven
#

The error tells that "Invalid config for [switch.mqtt]: [icon_template] is an invalid option for [switch.mqtt]. Check: switch.mqtt->icon_template. (See ?, line ?)."

ivory delta
#

Well it's not wrong. There's no setting for icon_template for that integration.

real raven
#

@ivory delta Thanks but how can I add such a setting to the integration?

ivory delta
#

You don't unless you're a developer. What are you trying to do?

mellow knot
#

still no go ๐Ÿ˜ฆ i used developer tools -> states to set sensor.elevation to 30 and my brightness is still at 1%

real raven
#

I like to have icons changed interactively in lovelace.

ivory delta
#

Then you probably need to look at whether you can have dynamic icons in whatever card you're using. Try over in #frontend-archived

ivory delta
mellow knot
#

i havent tried with sun.sun elevation using your template. let me give that a shot

ivory delta
#

Try it in the Dev Tools first and tell us what they give.

#

One step at a time... get the templates right, then worry about your automation.

inner mesa
#

there are really only two things that you need to work, and you can check them independently - that the trigger triggers on changes and that your formula in the template returns the value you expect

ivory delta
#

Exactly. Trying to get the latter right first since it's easier to 'see'.

#

Once the templates work as expected, it's easy enough to test the trigger.

mellow knot
#

at 33 degree using {{ ([state_attr('sun.sun', 'elevation')|float, 0]|max) * 4 }} gives 130.72

ivory delta
#

Great. Positive values. Tweak the factor how you'd like it.

#

Then use that template in your automation ๐Ÿ™‚

#

You already know you're going to be working with values from 0-90.

old wharf
#

Hi all! Pretty new to HA and trying to get better at coding. I have scrubbed through quite a bit of forums but I haven't found anything quite like I am after. I am trying to setup an automation for when everyone is away from home and to set the thermostat temp accordingly to the mode that it is in. Am I on the right track and can I use helpers in place of the values?

https://paste.ubuntu.com/p/2jcHNm8DTS/

ivory delta
#

Do you mean the section from line 23?

old wharf
#

Yes

#

Sorry. I also just realized I posted in the wrong channel...

ivory delta
#

That won't work. It'll return the strings 'input_text.heat_away' or 'input_text.cool_away'. You want the values from those inputs, right?

#

Nah, you're okay here. Your question is about the template ๐Ÿ˜‰

old wharf
#

Yes

ivory delta
#
data: "{{ states('input_text.heat_away')if is_state('climate.lyric_85db34', 'heat') else states('input_test.cool_away') }}"```
#

Meh. That looks messy on one line ๐Ÿ˜„

#

Multi-line:

data: >
  {% if is_state('climate.lyric_85db34', 'heat') %}
    {{ states('input_text.heat_away') }}
  {% else %}
    {{ states('input_test.cool_away') }}
  {% endif %}```
#

Both do the same thing. You need to use a template to extract the value before it's returned ๐Ÿ™‚

old wharf
#

Got it. I need to pull the states for that value.

#

I have the input as text with a numerical number. That won't be an issue right?

ivory delta
#

It should be okay. Whichever integration you're sending that data to should convert the data type if it needs to.

old wharf
#

Ok. It's a honeywell thermo using homekit

ivory delta
#

Should be fine ๐Ÿ™‚ Test it and see how it goes.

old wharf
#

Thank you!!! I will go work on it right now and test.

#

Error that I am getting

Invalid config for [automation]: expected dict for dictionary value @ data['action'][1]['data']. Got None. (See /config/configuration.yaml, line 9).

ivory delta
#

Oh... you'll probably need to assign the value to a key within data, not to data itself.

#

Probably the temperature setpoint.

old wharf
#

Oh I see. I need to put entity under the data

#

This is what I have so far

ivory delta
#

Yeah, data might need a few other things. Check the climate docs for that and if you're still stuck, head over to #integrations-archived

old wharf
#

That's what I was just looking at. Now visual studios isn't complaining ๐Ÿคž

#

Works as expected!

#

Thank you for your help! Really appreciate it!

ivory delta
#

No problem

cold hazel
#

hi, what Im doing wrong with mqtt sensor value_template:

#

value_template: "{% if is_state('sensor.kociol_zawor_co_cwu', '0') %} CO {% elif is_state('sensor.kociol_zawor_co_cwu', '100') %} CWU {% endif %}"

#

state from mqtt is 0 or 100

#

for 0 I would have state = CO, and for 100 state=CWU

cold hazel
#

value_template: "{% if ('sensor.kociol_zawor_co_cwu', '100') %} CO {% elif is_state('sensor.kociol_zawor_co_cwu', '100') %} CWU {% endif %}"

#

this one working ๐Ÿ˜„

thorny snow
#

I'm a bit confused again... I have a fan I can control with IR... so I'm using a broadlink thingie to send commands to it, which work just fine using some scripts like the documentation suggests... now I would like this fan to be a "fan" integration, so I create a "template fan". But it needs a "value template" and a "speed template" for knowing the state of the fan. I do not have any state of the fan other than a reasonable guess based on what signals I've sent it... how should I approach this? Can I make a "dummy" state for the fan... a best guess and use that to feed the template?

thorny snow
#

oh, never mind, I got it working now ๐Ÿ˜„

sinful bison
#

hello :)
I am encoutering something unexpecte with the change of template type.
I am trying to output the string 'None' but i always get an error string value is None for dictionary value @ data['option']
both with "{{ 'None' |string }}" and "{{ 'None' }}"
any idea why the template seam to return a None object rather than the string i ask ?

tribal relic
#

Is there a way to get the area of a device?

ivory delta
#

I don't think you can via templates. You have to go poking around in the UI or in the files the info is stored in.

#

Areas aren't incredibly useful yet. Groups make more sense.

tribal relic
#

Thanks ๐Ÿ™‚

silent barnBOT
north acorn
#

can someone help me with that question?

sinful bison
#

it doesn't look to bad. any idea what doesn't work ?

#

when i do it i have an extra tab in front of the template

        {%- if is_state("input_boolean.salon_ambiance", "on") -%}```
mellow knot
#

@ivory delta and @inner mesa thank you so much for helping me with solar elevation -> light brightness yesterday. Had to run out in a rush so never had a chance to thank you guys for all the help. Cheers.

sinful bison
#

yes @north acorn

#

also

it doesn't look to bad. any idea what doesn't work ?

north acorn
#

so, what I do know is that has to do wih the line itself. I tried by removing everyting and only use ["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"]

#

which does work

#

but when having that inside {% if is_state("input_select.wekker_alisina_spotify", "Global Top 50") %} ["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"]

#

then it doesn't woerk

#

no errors either

#

I made sure the input_select is correctly

#

selected

sinful bison
#

did you try it in the template page in developement tool ?

north acorn
#

that says: TemplateSyntaxError: Encountered unknown tag 'elif'.

#

but I have that template setup as well, with different parameters which does work: {% if is_state("input_select.wekker_alisina_speaker_lms", "Woonkamer") %} media_player.woonkamer_lms_original

#

this does work

#

So this is the whole code:

#

the entity_id part does work correctly, but the parameters part doesn't

#

if I remove the elif template and only leave the part behind it, it does work

sinful bison
#

just to make sure, try {% elif is_state("input_select.wekker_alisina_spotify", "Discover Weekly") %} {{ ["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"] }}

north acorn
#

doesn't work either

#

using only ["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"] does work

#

but the elif is_state part does work with other parts of the script, that's whats so confusiung

sinful bison
#

what about {%- elif is_state("input_select.wekker_alisina_spotify", "Discover Weekly") %} ["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"]

#

with the -

#

it generate it like parameters: >["play","spotify:playlist:37i9dQZEVXbMDoHDwVN2tF"], no new line

north acorn
#

yes correct, it's either that or:
`parameters:

  • play
  • spotify:playlist:37i9dQZEVXbMDoHDwVN2tF`
#

but I don't think I can template it like that

sinful bison
#

sure you can :)

north acorn
#

maybe that's worth a shot

#

how would I go about that?

sinful bison
#

let me find a working exemple

north acorn
#

my initial thought was:

`parameters:

  • play
  • elif_template here-spotify:playlist:37i9dQZEVXbMDoHDwVN2tF`
    But someone here told me to put them together instead
#

but I couldn't figure that out, so tried it with that other method

sinful bison
#

i don't know i'm not very good, i just know i have done it somewhere

#

for exemple i have done that before you could make list from template

        brightness: '255'
        effect: 'fade_blink'
        white_value: '0'
        rgb_color:
          - "{{ {'night': [0, 126, 255], 'total': [255, 0, 0], 'perimetric': [ 255, 63, 0 ]}.get(trigger.event.data.level)[0] }}"
          - "{{ {'night': [0, 126, 255], 'total': [255, 0, 0], 'perimetric': [ 255, 63, 0 ]}.get(trigger.event.data.level)[1] }}"
          - "{{ {'night': [0, 126, 255], 'total': [255, 0, 0], 'perimetric': [ 255, 63, 0 ]}.get(trigger.event.data.level)[2] }}"
north acorn
#

I think I have it working

sinful bison
#

๐Ÿ‘

north acorn
sinful bison
north acorn
#

haha

sinful bison
#

:p

north acorn
#

thanks for all your help!

#

I combined your code with what I had

#

and that did the trick somehow

#

having it as an array

sinful bison
#

happy that it work, surely not the cleanest but at some point you have to have something ;)

#

Because my own question is a bit burried now, i'll copy past it.

#

I am encoutering something unexpecte with the change of template type.
I am trying to output the string 'None' but i always get an error string value is None for dictionary value @ data['option']
both with "{{ 'None' |string }}" and "{{ 'None' }}"
any idea why the template seam to return a None object rather than the string i ask ?

primal ledge
#

Getting python errors from _template_changed_listener calling event.data.get("entity_id"), AttributeError: 'NoneType' object has no attribute 'data'

#

perhaps related to me using states.group.front_motion.last_changed ? Is there a more correct way to access the last_changed value?

#

Template works fine in the dev tools UI and the same template in a wait_template action in a automation is properly waiting while it evaluates to false but once it goes to true, it's throwing that error.

sinful bison
#

isn't last_changed something you can get with state_attr ?

primal ledge
#

doesn't appear so

#

doesn't work in the template editor UI

#

I'm not sure this is related to that use of that property actually.

#

trouble is, the Event parameter to that function is null which suggests something further up the stack is confused.

sinful bison
#

what do you have in trigger ?

primal ledge
#

{{ states('sensor.time') and states('group.foyer_motion') == 'off' and (as_timestamp(now()) - as_timestamp(states.group.foyer_motion.last_changed)) > 60 }}

#

This is an action triggered by the motion sensor group. An earlier action turns on lights. I've removed the later actions for now.

sinful bison
#

if this is your trigger, there is no entity id in your event

#

because it's not a state change

#

it's a template change

primal ledge
#

That method assumes a non-none event argument.

#

the calls to event.data are throwing an exception

ivory delta
#

Last changed isn't something you can get directly from the state object.

primal ledge
#

it works in the template editor UI

sinful bison
#

can't you just use a

    - platform: state
      entity_id: group.foyer_motion
      to:  off
      for: "00:01:00"
      ```
primal ledge
#

I tried a trigger action initiall but it never fires - stalls.

#

initially

sinful bison
#

right now your trigger is a template.
So the event object is empty
when you later call event.data.get("entity_id") you get an error because event don't have any data

#

to have those you need to use other type of trigger

primal ledge
#

So is this a bug?

#

How would a template trigger ever work?

sinful bison
#

it is a trigger, but just a trigger

#

you can't get the data like that

ivory delta
#

.share your config, Retentive

silent barnBOT
primal ledge
#

sorry, wait template, not trigger

#

@ivory delta, you want to see the automation?

sinful bison
#

yea please

ivory delta
#

Yes. Instead of being drip fed tiny pieces of information.

#

Let's see it all in context.

primal ledge
#

rgr, wilco

sinful bison
#

what the hell does this mean

primal ledge
#

sorry, "rgr" = "Roger" = "message received", "wilco" = "will comply". Military speak.

sinful bison
#

๐Ÿ‘Œ

primal ledge
#

old habits die hard

hollow rampart
#

Hello. Would someone please help me figure out fine tuning my blind template. It seems to work but Iโ€™m getting an error in template UI. I actually have to templates that work sort of ๐Ÿ˜€ Im also using Siri which also works but there is some sort of a loop in HomeKit because the when give a command the blind does open but the Siri just keeps spinning.

silent barnBOT
hollow rampart
#

This is what I have so far.

sinful bison
#

i was 100% off track @primal ledge , you should have send it before XD

ivory delta
#

What are you expecting to happen? You have a wait right at the end... that'll achieve nothing.

sinful bison
#

i will keep the automation 'running' i guess ...

ivory delta
#

'guess' ๐Ÿ˜‰

primal ledge
#

@ivory delta, I removed the later steps so I could be sure the errors wasn't coming from them.

ivory delta
#

Well as written, I wouldn't expect it to work.

primal ledge
#

wouldn't expect the template to work?

#

or the automation?

ivory delta
#

The automation

#

Plus there are likely better ways to achieve what you're trying to do... but that's also a discussion to have in #automations-archived

primal ledge
#

I never end up posting in the right group. my bad.

#

agreed. will head over there. sorry for the noise

sinful bison
#

@hollow rampart

          {% if states.light.left_blind_isy.attributes.brightness %}
            on
          {% else %}
            off
          {% endif %}```
please use `value_template: " {{ state_attr('light.left_blind_isy', 'brightness' ) > 0 }}"` or something like that first. calling state.light. ... will create error when the device is unknown
ivory delta
#

No problem. You have a template inside an automation, could've been either ๐Ÿ˜„

primal ledge
#

while I have you, is there a "correct" way to access that last_changed value in a template?

hollow rampart
#

Ok Iโ€™ll try it thank you.

sinful bison
#

why do you use a light brighness to set the on off if i may ask ?

ivory delta
#

The way I suggested earlier, Retentive.

sinful bison
#

what ? where mono ? i missed it to

ivory delta
hollow rampart
#

Ok so my controller is ISY. All zwave light devices come in at 0-100. When I bring the blind data in from ISY HA things itโ€™s a light. So I convert the light to cover domain. Than I want to fine tune the % open.

sinful bison
#

i actualy didn't see the difference and though you had just copy his exemple and said that it wasn't the right way XD

hollow rampart
#

Sorry Iโ€™m not sure if the question was for me?

sinful bison
#

it was :)

hollow rampart
#

Ok good than you

sinful bison
#

thank's for the reason, it make more sense

silent barnBOT
sinful bison
#

but doesn't the 'light' on off state from your controler match the open/close state of the blind @hollow rampart ?

hollow rampart
#

I changed the scale so that 0 is closed and position 100 in HA is actually 50% which is where the slats are horizontal.

warped hill
#

any jinji2 expert here ? try to convert string to json

sinful bison
#

How to prevent json encode
{{ attr | tojson }}
avoiding using tojson ?

hollow rampart
#

Yes but 50% is not perfectly horizontal so I was in the process of fine tuning by dividing position by say as an example 2.1 and so on.

#

I know in the template I have 2

warped hill
#

but I need to process the data in json

sinful bison
#

oki doki @hollow rampart, hop you get it working :)

hollow rampart
#

Thanks Iโ€™ll try your suggestion.

primal ledge
#

@sinful bison, using the trigger works now. I swear it didn't before.

#

lol

sinful bison
#

a blip in the system @primal ledge ;)

primal ledge
#

glitch in the matrix, yes

sinful bison
#

@warped hill i have no idea what you want to do, so i don't know how to help

warped hill
#

i try to replace 'Voltage': 3.12, with 'Voltage': 5 .. any good way to do this ?

#

where 3.12 is variable

sinful bison
#

don't save attr as a string, but as a array, and override that value ?

warped hill
#

how to make this states.binary_sensor[entity_id].attributes as dict ?

sinful bison
#

it is one when you get it

#

for exemple {{ states.media_player.tts_bureau.attributes }} return {'friendly_name': 'TTS_Bureau', 'supported_features': 65471}

warped hill
#

correct

#

assume now i want to change 'supported_features': 10

sinful bison
#

so {% set attr=states.media_player.tts_bureau.attributes %} {% set attr['supported_features']=10%} i guess

#

would have to try it

#

it doesn't work @warped hill

hollow rampart
#

@sinful bison so I tried the >1 change. So now when I close the blind it HA says it is unavailable which makes sense.

ivory delta
#

Why would you want to change the value of supported features?

warped hill
#

TemplateSyntaxError: expected token 'end of statement block'

sinful bison
#

it's an exemple about how to change a value from a saved array @ivory delta

warped hill
sinful bison
#

set don't allow it, and we don't have do in home assistant

ivory delta
#

You can't manipulate the values of an entity using templates. I'm curious why you want to try to do it.

sinful bison
#

we are using template :)

ivory delta
#

I know that.

#

I'm asking why.

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.

sinful bison
#

i try to replace 'Voltage': 3.12, with 'Voltage': 5 .. any good way to do this ?

ivory delta
#

I saw that. I'm asking why.

sinful bison
#

oh that i don't know.

#

sorry

ivory delta
#

No, you don't. So stop answering for them.

warped hill
#

i try collect the update and combine them and publish back to mqtt

ivory delta
#

So the device gives bad data and you want to correct the data?

warped hill
#

i want to update the attribute data

ivory delta
#

Okay. So just send your data directly to MQTT? Don't try to edit what's in HA.

warped hill
#

eg current attr is "BatteryVoltage":3.04,"BatteryPercentage":100

#

then i receive update "BatteryVoltage":3.06

#

how to update to "BatteryVoltage":3.06,"BatteryPercentage":100

ivory delta
#

Update what?

warped hill
#

Attribute

ivory delta
#

Where? What system? You can't update HA entities like that.

warped hill
#

i cant just publist BatteryVoltage":3.06

ivory delta
#

Why not? What reads the value from MQTT?

warped hill
#

if I publish BatteryVoltage":3.06. MQTT attribute will lost "BatteryPercentage":100

ivory delta
#

Ok... why does that matter? What reads the value from MQTT?

hollow rampart
#

@sinful bison so I tried the change to the template and now if I move the slider anything past 1 the blind becomes unavailable.

sinful bison
#

i may have made a mistake @hollow rampart

#

let me check

warped hill
#

it matter, i want to see both "BatteryVoltage":3.06,"BatteryPercentage":100 in attribute

hollow rampart
#

Is value template more for if the unit is on or off? Or should I use position template.

sinful bison
#

@hollow rampart what integration are you using ? template cover right ?

hollow rampart
#

I have that too

#

Yes

ivory delta
hollow rampart
#

Thank you btw

sinful bison
#

Valid values are open/true or opening/closing/closed/false

#

so true false should return open and closed but not available and unavailable ...

warped hill
ivory delta
#

Whatever reads from MQTT should only care about the new information.

sinful bison
#

you did use value_template @hollow rampart and not availability_template

ivory delta
#

If missing information breaks it, your other software is the problem.

#

Fix your other software ๐Ÿ˜‰

warped hill
#

each few second, it publish "BatteryVoltage":3.06 then "BatteryPercentage":100 then LinkQuality":42

#

IF i can dig the hardware out

hollow rampart
#

I never worked with availability template I can try it though

sinful bison
#

you don't need to, i just don't understand how this value changing make the device unavailable

warped hill
ivory delta
#

Yeah, we're done here. Bye.

sinful bison
#

could you send me what {{state_attr('light.left_blind_isy', 'brightness' )}} return in the template page on the developement tool ? both with it at 0 and like 10 ?

#

i'll have to go eat, be right back ;)

hollow rampart
#

Ok

#

Thanks

sinful bison
#

@warped hill FYI when i do {{attr=states.media_player.tts_bureau.attributes}} attr is a mappingproxy, which don't have a setattr methode. You might want to see how to convert that type :)

hollow rampart
#

When itโ€™s 0 equals None and when it is 100% opened it gives me 50.

#

Which is correct.

warped hill
hollow rampart
#

2 gives me 1 which makes sense since Iโ€™m dividing by 2 and converting into int with round

warped hill
#

{{ attr | regex_replace(''Voltage':.*?,', ''Voltage': 5')}}

warped hill
silent barnBOT
sinful bison
#

@hollow rampart try again with {{ state_attr('light.left_blind_isy', 'brightness' )|int > 0 }} just in case, and if it still become unavailabe, i would like for you to do the same test in the template field, but with the full line and not only the first part.

#

if you are still around that is

#

I am encoutering something unexpecte with the change of template type.
I am trying to output the string 'None' but i always get an error string value is None for dictionary value @ data['option']
both with "{{ 'None' |string }}" and "{{ 'None' }}"
any idea why the template seam to return a None object rather than the string i ask ?

ivory delta
#

You should share the full config, Vlycop. Hard to tell what's wrong only from that error message.

sinful bison
#

To make is simple only the action is needed

action:
    - service: input_select.select_option
      entity_id: input_select.vitrine_swarovski_preset
      data_template:
        option: "{{ 'None' |string }}"```
the "real" template is more complicated but the issue is with the 'None' rendering since the above don't work
`        option: "{{ 'None'|string if state_attr('light.vitrine_swarovski_segment_0','preset') != state_attr('light.vitrine_swarovski_segment_1','preset') else state_attr('light.vitrine_swarovski_segment_0','preset')|string }}"`
hollow rampart
#

Hello so I took the initial template and instead of on or off I changed it to open or closed according to the cover template guide. Looks like itโ€™s working.

#

Is that not the proper way to test for a string? Just checking.

sinful bison
#

i don't understand what you did, sorry. They was no string in the template

silent barnBOT
hollow rampart
#

Ok this is what I changed

#

If there is a better way to do this I will follow your suggestion.

sinful bison
#

{% if states.light.left_blind_isy.attributes.brightness %} <- this is bad.

#

plus i have no idea what does the if check for

#

if the only issue is the word, i would use {{ 'open' if state_attr('light.left_blind_isy', 'brightness' )|int > 0 else 'close' }} but i am guessing what didn't work before was the if and not the word ...

ivory delta
#

I don't know why you're using |string everywhere, Vlycop. Most templates will return strings anyway.

#

And if you're quoting None, it's not the type None, it's the string 'None'.

hollow rampart
#

@sinful bison I tried the above change and the error message is saying that Iโ€™m missing a comma at column 35.

sinful bison
#

@ivory delta i have put |string everywhere because no mater what i try i get a type None

#

causing the error

ivory delta
#

If HA is converting 'None' back to None after it's evaluated the templates, you can't control that. Try with another word instead of 'None' that doesn't have a special meaning.

sinful bison
#

i can't ... i am getting the value from something i don't control :(

ivory delta
#

It's a bad idea (and often forbidden) in most languages to use keywords.

#

'None'|string is yours.

#

Use 'N/A' or 'banana' or something instead.

sinful bison
#

state_attr('light.vitrine_swarovski_segment_0','preset')|string retrurn None

ivory delta
#

Which is fine when it's inside the template.

sinful bison
#

the other bit is only to manualy set it to none if i get data that don't match what is expected

hollow rampart
#

But it works in template editor. Geez

ivory delta
#

Your template can do whatever it wants. Once it's evaluated and the value passed to something else, the next thing will try to use the value.

sinful bison
ivory delta
#

It's apparently seeing 'None' from your template and turning it into None. That's not a problem you can solve within your template.

sinful bison
#

i'll open an issue to see if there is a drawback to block that convertion. This is new the the change of what type template return, it didn't happend in 116.

#

thank's

ivory delta
#

You're missing the point.

#

You're setting the value of an input_select, right? Instead of having an option called 'None', call it something else.

sinful bison
#

i'll have to convert the data both when i write it (here) and when i read it (another automation).
I can do that, but it's still not normal, if i want to send a notification with the word None, i should be able to do it.

ivory delta
#

Maybe the devs can think of a way round it. I can't. I agree that the new functionality makes some cases tricky, but they're not just going to undo the native types stuff they added.

sinful bison
#

off course they won't ! but this more like an edge case they didn't found than a deliberate choice

ivory delta
#

I think you're right to open an issue for it though. I've seen similar before, just not with keywords.

#

Well it's tricky. You either allow HA to interpret the result of a template as native types or you don't. I don't know how they could add any 'middle ground'.

#

You don't want 'None' to become None. Other people will. Can't do both.

#

Log an issue and at least it'll start a discussion with the devs ๐Ÿ™‚

sinful bison
#

i think that with the new way type are being send, you should send use None when you want it and 'None' when you need the string. We will see what they think of it when they have time

ivory delta
#

I think the issue is that Jinja returns a string and HA interprets it.

#

Remember, templates used to always be a string, even if what you thought you were returning was another type (dict/list/etc)

hollow rampart
#

value_template: {{ 'open' if state_attr('light.left_blind_isy', 'brightness' ) | int > 0 else 'closedโ€™ }}

#

Ok so this is what I typed in

#

It looks good but it is still telling me there is an error after open

inner mesa
#

Double quotes around the whole thing

hollow rampart
#

Ahh

inner mesa
#

Rule #1

hollow rampart
#

Got it

ivory delta
hollow rampart
#

Thank you everyone that works!!

sinful bison
#

Sorry i was busy with other thing, i didn't saw your reply

trail ginkgo
#

I have a template switch, which reads the value of a sensor and is on or off depending on that value. Now, I have two challenges :

  1. When I manually flip the switch, it takes 10-20 seconds for the sensor to catch up. So what happens is that the switch flips back to the reverse position and then flip again. (eg. I turn it on, it then turns off within a few seconds and 10-20 seconds later turns back on again)

  2. For whatever reason, the sensor sometimes has an insane value for a single reason. Because of this, the switch will flip to 'on' for 10 seconds (the sensor update frequency). So I'm wondering if there is a way to template the sensor reading "having been above X for Y seconds".

fossil hearth
#
sensor.rpi_milksensor_script_process_1:
  icon: mdi:application
  icon_color:
      templates: >
        return (state === 's') ? 'rgb(67,167,47)' : 'rgb(219,27,8)';

please someone help what do i need to do its not working , have been trying for a week now.
this is in my customize.yaml

inner mesa
#

Do you have custom_ui installed? Where did you get that syntax from?

fossil hearth
#

@inner mesa i think i have installed it , how can i check ? also i got it from previous discussions here in the group

#

am soo pissed man haha , a week, am trying not to be Spammy here in the group waiting patently haha

inner mesa
#

I donโ€™t use it anymore. I think youโ€™ll see it somewhere in configuration -> Info

#

But youโ€™d know if you installed it

fossil hearth
#

i know i installed it ..