#templates-archived

1 messages Β· Page 109 of 1

pure pulsar
#

++ @charred dagger

#

Thanks @charred dagger

rain condor
#

ah @coarse tiger @charred dagger setting the right chmod on id_rsa fixed it, I was testing as non root and it worked but when testing as root it complained that it had to many permissions chmod 600 id_rsa

charred dagger
#

TIL. Thanks for reporting back

buoyant pine
#

++
@pure pulsar FYI there's no karma on this server if that's what you were trying to do

inner mesa
#

I just figured they were trying to wake thomasloven up

peak juniper
#

Not sure where to post this but figured this might be the best place. When I switch my LG TV off via the frontend it turns off immediately but takes a while for the icon to update on my frontend. Is there a way around this by making some kind of template that shows off it's toggled off

inner mesa
#

does the state change immediately or is it also delayed?

#

devtools -> States

peak juniper
#

state seems to be delayed too

inner mesa
#

then not much that you can do

peak juniper
#

is there any way to say if I turn the TV on via the template switch, it shows on for a few seconds until it can check if the TV is on and vice versa for when it turns off?

inner mesa
#

sure. you define the state value

#

use an input_boolean or something

#

you probably can't make the TV or the integration respond faster, but you can just maintain your own "optimistic" state

#

or just leave the value off entirely, and it will just assume

buoyant pine
#

Yeah, the reason for the delay is because that integration is polling, not push

#

Home assistant might ask for the state right away after changing it, but if that's the case the TV must not report an updated state when that happens so it doesn't get updated until the next polling interval

peak juniper
#

If I left the value_template out of the template switch, it would only show on or off if toggled or you say it would assume..what..based on what?

inner mesa
#

as in the docs:

#

value_template template (optional, default: optimistic)
Defines a template to set the state of the switch. If not defined, the switch will optimistically assume all commands are successful.

buoyant pine
#

I'd say you just leave it as is and deal with the delay

peak juniper
#

Home assistant might ask for the state right away after changing it, but if that's the case the TV must not report an updated state when that happens so it doesn't get updated until the next polling interval
@buoyant pine thanks for the explanation. It really is such a minimal delay but it's the little things that if I have the power to tweak, great, if not, then I guess I can live with it πŸ˜„

#

that's probably the best option, aside from an overly complex setup which will probably not work 100% as intended

#

I imagine I could set its value_template to an input boolean, which is managed by automations polling the state of the TV

#

so if I set the switch to off, it will set the input boolean to off, and an automation would turn the TV off based on the state change of the input boolean

#

then if I set the switch on, the TV will turn on and automation watching for state changes to the mediaplayer can set the input boolean to on...

#

do you think that kind of makes sense?

#

probably not worth it at all mind you

inner mesa
#

sure

peak juniper
#

haha, maybe I'll leave it - I feel like too many things you don't expect to go wrong can go wrong when you overcomplicate things

#

thanks both for being sounding boards though πŸ™‚

feral turtle
#

Howdy

#

a simple question it' possible de define a severity value lovelace Gauge from an input number ?

ivory delta
#

The gauge card doesn't care that it's an input_number. Your question is about the gauge card, you're better off asking in #frontend-archived

storm gazelle
#

Hey, does anyone see what's wrong here? Just checking if a device is offline

binary_sensor:
  - platform: template
    sensors:
      LR_unavailable:
        value_template: >-
          {{ is_state('light.yeelight_2','unavailable') }}
#

(getting an error)

buoyant pine
#

And that error is...?

#

I see what the problem is but...

silent barnBOT
#

Please don't say I have an error or describe an error. Share the whole actual error message so we can help you.

arctic sorrel
#

100% probability it's the slug πŸ˜‰

#

If we can spot that without the error, just think how much easier it'd be with the error message to help us

storm gazelle
#

Yeah, good point. The error is about formatting I suppose, but I have some hard time trying to copy text from console after I read your msg.

arctic sorrel
#

🀷

#

Use a proper SSH client and you'll be able to copy and paste more easily πŸ˜‰

buoyant pine
#

Regardless the error message should tell you what the solution is, something like (try lr_unavailable)

storm gazelle
#

OK maybe I just don't understand the terminology.
It tells me about invalid slug, and so do you

#

I have no idea what it is xD

buoyant pine
#

Heh...it's the thing in the fourth line in what you posted

storm gazelle
#

oh crap

#

no caps?

buoyant pine
#

Understandable to not know the term

#

Yeah

storm gazelle
#

daaaaaamn

buoyant pine
#

See the link Tinkerer posted above

storm gazelle
#

Thanks!

buoyant pine
#

No caps in entity IDs (and the slug determines the entity ID)

arctic sorrel
#

The error message also is telling you what to use instead

storm gazelle
#

Hmm, you're right. I was focusing too much on technical output and missed that

ivory delta
#

Something something forest, something something trees.

nocturne chasm
#

Can’t see the something something through the something something

buoyant pine
#

|| something something 🀏 something something ||

nocturne chasm
#

|Docker|

buoyant pine
#

Yes

nocturne chasm
#

Aw crap. Forget it

buoyant pine
#

|| text ||

nocturne chasm
#

Yea...that

buoyant pine
#

|| 🀏 ||

nocturne chasm
#

|| docker ||

#

If I had a brain I would be dangerous 🀣

thorny snow
#

I'm failing on the syntax for making a template sensor that parses a json object and gets one value out... it's a small json object read from a file sensor already and I just want to put the json values into separate sensors.

thorny snow
#

I get the states of the entity and I to_json it but testing the template in devtools trying to access the values inside gives me no output. But printing the whole json object out as json works fine

#

AH got it {{ (states('sensor.XXX') | from_json).name }} that wasn't so hard πŸ˜„

#

Hmm, but just because it works in devtools, doesn't mean it works in the configuration file. 😦

thorny snow
#

I'm so confused... why couldn't I write this {{ (states('sensor.XXX') | from_json).name }} in a value_template on a template sensor?

#

It works just fine in the devtools template editor

silent barnBOT
#

5 Rules for better support:

  1. Be very specific about the issue/problem you are facing (a problem clearly stated is a problem half solved)
  2. Absolutely NO negative comments about individuals, developers or the community
  3. Read the documentation (RTFM). It is an open source product, you are allowed to contribute, but not whine
  4. Every setup is unique in its own way. Share your config, code, logs and other relevant info via https://hasteb.in/ or https://paste.ubuntu.com/ - don't post walls of text in the channels
  5. Keep the channel live by being friendly, offer help where you can, learn when you can't!
  6. Remember to review #rules

We are thankful to all the members who dedicate their personal time helping others.

waxen rune
#

ok, that worked πŸ™‚

fossil hearth
#

Hi guys :)
hi, does anyone know how to narrow down this further? the result is too big

curl -X GET http://192.168.40.210:61208/api/3/processlist/name/rpi-temperature

For isntance i want it to show the status in the api

output: https://paste.ubuntu.com/p/wqy3bPynvt/

#

The result is too big for the rest api, must narrow it down .

charred dagger
#

Where? A command line sensor?

#

If so, you can use value_template. That parses json

thorny snow
#

oh... the solution was to not do a one liner.... the syntax was correct but i had to split it apart like so: value_template: >- {% set value = states('sensor.host_network_control') | from_json %}
{{ value.tunnel }}

fossil hearth
#

Where? A command line sensor?
@charred dagger yes command line sesnor πŸ™‚ and i have 5 rpi-temperature running :/

charred dagger
#

@thorny snow {{ (states('sensor.host_network_control') | from_json).tunnel }} should work then.

thorny snow
#

@thorny snow {{ (states('sensor.host_network_control') | from_json).tunnel }} should work then.
@charred dagger I agree, that's what made me confused... when I checked the config it gave me an error.

fossil hearth
#

@charred dagger

sensor test:
  - platform: command_line
    name: Used mem
    command: "/usr/bin/curl curl -X GET http://192.168.40.210:61208/api/3/processlist/name/rpi-temperature"
    value_template: '{{ value_json["rpi-temperature"][0][["status"]] }}'

output of the curl: https://paste.ubuntu.com/p/wqy3bPynvt/

πŸ˜„

#

what should i do 😳

#

sorry ignore the name i was testing ( used mem) its irrelevant

fossil hearth
#

Its all good i did it πŸ™‚

fossil hearth
#

how can i change the color if my state is "S" in customize for my dashboard

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

whats my problem here 😦 ?

dreamy sinew
#

need to use actual template syntax

silent barnBOT
mighty ledge
#

@fossil hearth you need to wrap it in quotes. or use multiline notation. Also, that code requires that CustomUI is installed.

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

@dreamy sinew thats CustomUI js templating

dreamy sinew
#

ah

mighty ledge
#

yeah, it's a thing of the past

#

but some peeps still use it

#

problem is, beginners don't know the difference

dreamy sinew
#

mods too apparently πŸ˜›

mighty ledge
#

Na, I mean, beginners search the forums for "change color based on state" and they find all the CustomUI templates and think it will work

dreamy sinew
#

i definitely recognized it as JS but thought it was just standard bad syntax errors

mighty ledge
#

I just realized it had syntax errors too

#

oops

torn meteor
#

i think i asked this before, but is there a way to "wrap" a configuration entity in a device, so that it can be assigned to an Area?

dreamy sinew
#

no

torn meteor
#

so there is absolutely no way to put orphan entities in a room.

ivory delta
#

That's a great idea. Put them in the basement where orphans belong.

buoyant pine
#

No, only Devicesℒ️ can be assigned to areas

#

Even then, areas still aren't particularly useful

torn meteor
#

would you suggest a group object instead? oh wait, groups can't be added to areas either

#

i suppose it's down to custotmizing the front end then

charred dagger
#

Areas affect the auto generated layout and can be used with most services that take a list of entities, so they're definitely useful.

buoyant pine
#

Ah, didn't realize that about the auto-generated layout

torn meteor
#

(yeah, i'm still using the default automated layout. Room A has lights 1,2,3, but the "Lights" group is 20 miles down the page for entities that belong to Room A as well)

ivory delta
#

There's always groups. I believe they take priority over areas.

torn meteor
#

Do groups appear as lovelace cards like areas do?

ivory delta
#

As in do multiple entities appear together in a single card? Yes

#

I have a group with most of my lights in (so I can turn that group off in one go) and they appear together.

torn meteor
#

ok. That works then πŸ™‚

hollow obsidian
#

how can I build a list starting from a string with value separed by / ?

rugged laurel
#

{{"foo/bar".split("/")}}

hollow obsidian
#

?

#

{{ states('sensor.vento_tosko')[1] | pprint() }}

ivory delta
#

What does your template output?

hollow obsidian
#

it is '34 / doen / yeep / poke / wsw'

#

i need t extract the third element

#

yeep

ivory delta
#

What does states('sensor.vento_tosko')[1] output?

hollow obsidian
#

[1] give ''

#

' '

#

I was planning to ask [3] to extract the thirs, but i neeed to convert into a list. isn't it?

ivory delta
#

Ok... let's step right back... what's the full output of that sensor's state?

hollow obsidian
#

the full output, retrieved with PPRINT() is

#

'\n 3.2\r\n Km/h - WNW\r\n\n'

#

so I want to extract the WNW

ivory delta
#

Without pretty print. Without any templating or functions. Just the value of states('sensor.vento_tosko')

hollow obsidian
#

4.8 Km/h - WNW

ivory delta
#

Try {{ states('sensor.vento_tosko').split(' - ')[1] }}

hollow obsidian
#

this sounds good

#

WNW

#

πŸ‘

ivory delta
#

it is '34 / doen / yeep / poke / wsw'
i need t extract the third element
So all of this was bad information. That doesn't help us help you.

#

Start with facts πŸ™‚

hollow obsidian
#

sure!

#

sorry I was starting by the ends

#

thank you alot

small hemlock
#

hi, to provide an additional layer of security, I would like to add a security token (for instance a hash of the current date and a shared key) to the body of an MQTT payload that I publish to the broker via an automation. What would be the best approach to do this (generate the token and dynamically add it to the payload)?

coarse tiger
#

how do you want to verify the token?

small hemlock
#

Verification is done on the receiving end via a python script

coarse tiger
small hemlock
#

Hmmm, how would I go about creating the token through templating? Should I use a custom filter for that? Or can I just use python code in Jinja? (Encryption libraries)

ivory delta
#

I think you're limited to what's available in Jinja 2 and whatever native stuff Python can do with basic data types (strings, lists, tuples, etc).

#

But this all begs the question: why? If your MQTT isn't public, it's already secure.

small hemlock
#

Yeah, I might be overthinking it... :)

#

I'm gonna check out templating just for the fun of it, if it takes too long, I'll do it without

weary garnet
#

okay so how does one take a test template from the one in developer tools and apply it? Where does it go?

waxen rune
#

that kind of depends on the template πŸ™‚

weary garnet
#

value template for climate entity

#

mqtt climate entity

waxen rune
#

well, if you describe what you are trying to achieve and share your template it's more likely to get your question answered

weary garnet
#

its a long story you ready?

waxen rune
#

well, shoot. but try to stay on the path

weary garnet
#

okay so i have a thermostat through MQTT and it sends its data thru the climate entity/intergration.. in Celsius.. I am from the states and would like to view it in Fahrenheit. change the unit of measurement doesnt work it doesnt convert the data.. I went into the template tool and wrote something in to do it ... it works but now I dont know what to do with it.

buoyant pine
#

Sounds like you want a template sensor

weary garnet
#

well thats what i tought too but config keeps yelling at me saying nope

ivory delta
#

The one command the bot doesn't understand 🀣

buoyant pine
#

Ehh, it should be .template but that's taken by another command and I keep forgetting

#

So...let's see the config @weary garnet

silent barnBOT
weary garnet
#

oh boy i will try this but it tends to not work as I am beind PIhole

buoyant pine
#

If it's under 15 lines you can post it here

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

weary garnet
#
  • platform: template
    sensors:
    set_temperature:
    entity_id: climate.bathroomfloor
    friendly_name: Set Temperature
    unit_of_measurement: 'F'
    value_template: '{{ (((states.climate.bathroomfloor.attributes.temperature) * 9 / 5) + 32) | round(1) }}'
buoyant pine
#

Please read the bot message above your message

#

Also share the error message

weary garnet
#

Invalid config for [sensor.template]: expected dictionary for dictionary value @ data['sensors']. Got None
extra keys not allowed @ data['set_temperature']. Got OrderedDict([('entity_id', 'climate.bathroomfloor'), ('friendly_name', 'Set Temperature'), ('unit_of_measurement', 'F'), ('value_template', '{{ (((states.climate.bathroomfloor.attributes.temperature) * 9 / 5) + 32) | round(1) }}')]). (See ?, line ?).

buoyant pine
#

Indentation issue

weary garnet
#

show me please

buoyant pine
#

Particularly under sensors:

weary garnet
#

and ya know in the yaml checker it checks off fine

buoyant pine
#

In the future please follow this when sharing code here instead of pastebin, otherwise it's really hard to see the indentation: #templates-archived message

#

What YAML checker?

weary garnet
#

when you go to edit any yaml

buoyant pine
#

?

weary garnet
#

the green check in the upper right

#

file editor

buoyant pine
#

Ah, I don't have add-ons so I didn't know what you were talking about

#

Yeah, don't trust that heh

weary garnet
#

okay so yea that checked out..

#

for each value i want converted it needs its own template entry yes?

buoyant pine
#

Yeah

weary garnet
#

ill let you know how it goes...

waxen rune
#

I left to get a coffee and some popcorn. When I come back there's no story left. This forum is too efficient.

left fossil
#

Right, masters of templating. I have a little flask app, delivering some content to a local host from a csv that changes. I've got restful sensor, and if I go to template editor with {{states('sensor.cinema_paradiso')}} I get https://hastebin.com/bagufisemu.json What I'm trying to get to is the text that would fill 'Fairy Tale: A Trust story' (a few others, but that'll probably be enough tog et me started) Tried a few things and cannot make it work

#

I have tried multiple options, I am a failure πŸ˜‚

ivory delta
#

{{ states('sensor.cinema_paradiso').data.Name['0'] }} should do it

#

If that last key hadn't been a number, you could've done it without the weird square bracket notation like this: {{ states('sensor.cinema_paradiso').data.Name.one }}. Keys starting with numbers don't play nicely with templates.

left fossil
#

I am getting UndefinedError: 'str object' has no attribute 'data' For what it's worth, the haste in automatically read as json, in theory the flask app should be returning json (jsonify) but who knows.

deft timber
#

You need to first convert the state value to a json :

#
{{ (states('sensor.cinema_paradiso') | from_json).data.Name['0'] }}
left fossil
#

Winner winner!

#

Thank you. I've been trying to work out how to feed stuff from my Python stuff into HA, and thought I'd have to create a whole integration - this is definitely the better option

ivory delta
#

I should've realised that it wouldn't auto-cast the string to an object. I hope the rest makes sense to you πŸ™‚

left fossil
#

Yeah, I wasn't far off of it, and all the language is basically python string manipulation familiar enough that it makes sense πŸ˜‚

ivory delta
#

Yes. The templates in HA use a mix of Python and Jinja 2 stuff.

left fossil
#

Yeah it's not perfect, but it's close enough πŸ˜‚

thorny snow
#

I am trying to figure out this automation, but it doesnt work. Can someone see whats wrong?

alias: Ny automasjon
description: ''
trigger:

  • platform: template
    value_template: ' {% if (''states.sensor.nordpool_kwh_oslo_nok_3_10_025'') > (''states.sensor.off_peak1_sensor'') %}{% endif %}'
    condition: []
    action:
  • service: switch.turn_on
    data: {}
    entity_id: switch.telldus_tzwp_102_plug_in_switch_switch
    mode: single
inner mesa
#

Not without more info on what you’re trying to do and what isn’t working

#

Your template is pretty broken, though

#

Syntax is all wrong

silent barnBOT
thorny snow
#

Works fine in developer tools, i am trying to run a automation when the electricity price exceeds off peak

buoyant pine
#

Just do "{{ states('sensor.whatever') | float > states('sensor.whatever2') | float }}"

thorny snow
#

Thank you @buoyant pine ! 😊 I get true and false in dev tools, but it will still not trigger the automation. Im pretty new to templates

silent barnBOT
#

To test an automation there's three stages you can follow. Testing the action, the condition and action, and the whole automation:

  1. Use Developer tools (devtools)-> States to find the automation, click info and then push Execute. If this fails your problem is in the action: section, and details should be found in your log file
  2. Use Developer tools -> Services and call automation.trigger on the automation with skip_condition: false. If the first passes but this fails then the problem is in your condition: block
  3. Use Developer tools -> States to find the trigger entity, click the name, then change the state (at the top) to something that'll trigger the automation before pushing Set State. If this fails then the problem is with your trigger: section.

If they all work, and your automation didn't run, it's probably turned off.

azure tinsel
#

is there any way to see logged in user as template? {{ hass.user }} or something ?

brazen harbor
azure tinsel
#

i does not work on template.. but ill try, thank you

#

yeah.. it does work on that markdown card

#

sadly i wanted to use it on another card but maybe it is not available πŸ™‚

brazen harbor
#

Is there a way to reuse parts of yaml in a template sensor? I have the following template that works, but uses a lot of repeating characters. Here is a just one component of it:
{{ state_attr('sensor.radarr_disk_space', 'X:\\')[0:state_attr('sensor.radarr_disk_space', 'X:\\').find("/")] | float + state_attr('sensor.radarr_disk_space', 'Y:\\')[0:state_attr('sensor.radarr_disk_space', 'Y:\\').find("/")] | float }}

brisk temple
#

you can shorten if if you define the repeating characters {% set repeat = whatyouwantrepeated %}

#

then just use repeat in your template

brazen harbor
#

Like this:

{% set repeat1 = state_attr('sensor.radarr_disk_space', 'X:\\') %}
{% set repeat1 = state_attr('sensor.radarr_disk_space', 'Y:\\') %}
{{ repeat1[0:repeat1.find("/")] | float + repeat2[0:repeat2.find("/")] | float }}
brisk temple
#

that second line should be repeat2

brazen harbor
#

Oh yea, oops, that's my bad. Meant to change that. But other than that, is it the correct idea?

brisk temple
#

ya

grim flicker
#

I would like to round a value to 2 decimals so far i have this which does work but doesnt round the number any thoughts?

{{ states('sensor.meterstand_kwh_hoog') | round(2) - states('input_number.stroomverbruik_hoog_per_maand') | round(2) }}
brisk temple
#

try {{ (states('sensor.meterstand_kwh_hoog') - states('input_number.stroomverbruik_hoog_per_maand')) | round(2) }}

grim flicker
#

that will give this error TypeError: unsupported operand type(s) for -: 'str' and 'str'

brisk temple
#

{{ (states('sensor.meterstand_kwh_hoog') | float- states('input_number.stroomverbruik_hoog_per_maand') | float) | round(2) }}

#

should float not int

wooden cypress
#

Hi All,
Hope this is the right channel.
Quick question with the Alarm Panel i see it only allows for certain states to be used such as armed, disarmed, armed_night etc. is there a way in the config to tell it that sleep is armed_night or do I need to modify these values before they are processed by HA ?

grim flicker
#

that last one worked thanks

brisk temple
#

@grim flicker your states were strings which is why the | float was needed

grim flicker
#

iΒ΄m just starting to use templates so i have allot to learn

grim flicker
#

so now i want to calculate what the usage costs are so i want to do the value *0.22 and want to round it to 2 decimals

#

i have tried a few options but they dont round

#

{{ (states('sensor.meterstand_kwh_hoog') | float - states('input_number.stroomverbruik_hoog_per_maand') | float) * 0.22 | round(3) }}

#

this doesnt round

brisk temple
#

what are you trying to multiply 0.22, just the input_number?

waxen rune
#

this examples rounds {{ ( states('sensor.washing_machine_voltage') | float - states('sensor.washing_machine_voltage') | float ) | round(0) }}

brisk temple
#

oh he wrapped the sensor and input_number, needs to wrap the * 0.22 as well

waxen rune
#

yep

#

and round(3)will give you 3 decimals, you mentioned you want (2)

brisk temple
#

it's a separate equation

waxen rune
#

sometimes it's easier to set it up like this. makes the actual math simpler:

      value_template: >-
          {% set t1 = (states('sensor.burner1') | float ) %}
          {% set t2 = (states('sensor.burner2') | float ) %}
          {% set t3 = (states('sensor.burner3') | float ) %}
          # And then the actual math, not your case below
          {{ ((t2-t1)/(t3-t1) * 100) | round(2) }}
grim flicker
#

thank you i will try this. What does | float do

inner mesa
#

Converts the value to a floating point number

silent barnBOT
grim flicker
#

when i copy the template part in the developers section to test it. the value is coming out. so it must be the rest of the code that isnt working

brisk temple
#

has sensor.meterstand_kwh_hoog changed state

grim flicker
#

yes it changes every 10 seconds its loaded out of my meter

inner mesa
#

Is the automation enabled?

brisk temple
#

are value and value_template the same now?

#

the example shows value

grim flicker
#

its enabled

#

yeah

brisk temple
#

change it to value

grim flicker
#

yes! that was the problem

#

thanks

azure tinsel
#

how can i get min value ot temperature from sensor for today?
with statistics i can get for last X hours, but i want only for today, for example if its 00:05 now and i have only one measure on sensor.temperature - this to be min

silent barnBOT
azure tinsel
#

this one need two sensors

#

and will give you min from them

#

but will not give you min value for today from one sensor

#

this one only compare two sensors

buoyant pine
#

Ah right

azure tinsel
#

something like history stats

#

i use history stats to counting running time for today, and it is OK, it resets at 00:00

buoyant pine
#

It was the first thing I thought of, but I realized I haven't looked at the docs for it lol

azure tinsel
#

but statistics platform does not

mighty ledge
#

@azure tinsel you can use the SQL integration but you need to build the lookup yourself.

azure tinsel
#

yeah.. but i need to switch everything to mysql? or i can use that with the default sqlite database ?

mighty ledge
#

yeah you'd probably need to swap over

azure tinsel
#

thanks

waxen rune
#

@grim flicker Sorry, old example code. Good to see you solved it!

azure tinsel
#

@mighty ledge it maybe can be done with sqlite too, thanks for the hint

mighty ledge
#

Yeah I don't know how sqlite works with multiple fingers in the pot

azure tinsel
#

sqlite> select min(state) from states where entity_id = "sensor.bedroom_temperature" and created > date('now');
18.8

#

looks OK

#

i will only query it

#

if it crash something ill migrate to mysql πŸ™‚

wraith shell
#

Hi everyone. I have retrieved a date with a scrape sensor from a website which is showing in HA in this format: 07/11/2020 - 16:45

#

is there any way to transform this format to something readable by HA so I can use this date in automations?

#

date will alwats be in the future

#

like 20/11/2020 - 16:45

#

always*

north locust
#

i have 2 things set up in templates , but how do i integrate them into cards ?

#

{{ (states('sensor.speedtest_download') | float * 1) | round(0) }}
{{ (states('sensor.speedtest_upload') | float * 1) | round(0) }}

#

and afval_vandaag:
friendly_name: 'Afval Vandaag'
value_template: >-
{% if states('sensor.areareiniging_gft') != None and as_timestamp(states('sensor.date')) == as_timestamp(states('sensor.areareiniging_gft')) %}
Gft
{% elif states('sensor.areareiniging_pmd') != None and as_timestamp(states('sensor.date')) == as_timestamp(states('sensor.areareiniging_pmd')) %}
Plastic
{% elif states('sensor.areareiniging_restafval') != None and as_timestamp(states('sensor.date')) == as_timestamp(states('sensor.areareiniging_restafval')) %}
Restafval
{% else %}
None
{% endif %}

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

waxen rune
#

@north locust what is the problem, does the templates work already?

waxen rune
#

@wraith shell I am sure there is a much better way, but I did this when I needed what you're after.
Basically it breaks down the data into a list of separate characters and then put them together again and as a last step format as time stamp.
Maybe worth a try? Just note it will only work as long as your indata always have the same number of characters.

{% set t = states('sensor.yoursensor') %}
{% set t = t | list  %}
{% set day = t[0]+t[1] %}
{% set month = t[3]+t[4] %}
{% set year = t[6]+t[7]+t[8]+t[9] %}
{% set hour = t[13]+t[14] %}
{% set min = t[16]+t[17] %}
{{ as_timestamp(year + month + day + " " + hour + min ) | timestamp_local }}

Output in my case: 2020-11-07 16:45:00

north locust
#

@waxen rune In the developer template it outputs fine , but adding it in my congiguration.yaml gives problems ...

waxen rune
#

do you want the template directly in the card or do you create a template sensor?

north locust
#

afval_vandaag:
friendly_name: 'Afval Vandaag'
value_template: >-
{% if states('sensor.areareiniging_gft') != None and as_timestamp(states('sensor.date')) == as_timestamp(
Gft
{% elif states('sensor.areareiniging_pmd') != None and as_timestamp(states('sensor.date')) == as_timestam
Plastic
{% elif states('sensor.areareiniging_restafval') != None and as_timestamp(states('sensor.date')) == as_ti
Restafval
{% else %}
None
{% endif %}

waxen rune
#

please use the backticks

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

north locust
#

this one doesnt need to be in a card

waxen rune
#

so much easier to read

north locust
#

want to make an automation with it

#

but everytime i add it in my config.yaml , log spits out errors

waxen rune
#

it seems cut off, can you please share the complete code? from sensor:

north locust
#

oops

#

will repaste

waxen rune
#

ok, have you tried out each value and condition separately in dev tools so you know they work as intended?

north locust
#

this is from sensor:

waxen rune
#

line 27 is cut off

north locust
#

yeah cut and paste from putty

#

but is complete

#

in yaml

waxen rune
#

ok, have you tried out each value and condition separately in dev tools so you know they work as intended?
the state None is unusual, maybe should have quotation marks? but as long as it works in dev tools, it should work.

ivory delta
#

None is a keyword in Python, it should be valid in that context.

waxen rune
#

ah. null in my world.

#

TIL

#

again

north locust
#

got it !

#

thanks !!

waxen rune
#

what was the solution?

north locust
#

indentation and spacing issue

#

:-0

north locust
#

editing in vi

#

πŸ˜›

peak juniper
#

Is there any way to create a state template for a history stats sensor

#

For example:

  • platform: history_stats
    name: Current Game History
    entity_id: sensor.xbox_online
    value_template: '{{ states.sensor.xbox_online.state }}'
    type: time
    start: '{{ now().replace(day=1).replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
#

so it dynamically shows me how much I've played the specific game I'm playing at that moment

brisk temple
#

does it display what game your playing?

peak juniper
#

the config doesn't accept the template

#

so the sensor.xbox_online shows what game I'm currently playing

#

let's saying it's "Assassin's Creed" currently

ivory delta
#

That's because you can't just make things up and expect them to work. The docs don't say it takes a template for the value. πŸ˜‰

peak juniper
#

then I would want the sensor to essentially show:

  - platform: history_stats
    name: Current Game History
    entity_id: sensor.xbox_online
    state: 'Assassin's Creed'
    type: time
    start: '{{ now().replace(day=1).replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'
ivory delta
#

It tracks a single state. Make a sensor for each state you want to track.

peak juniper
#

That's because you can't just make things up and expect them to work. The docs don't say it takes a template for the value. πŸ˜‰
@ivory delta haha yeah, I realise that - just wondering if there were any work arounds

ivory delta
#

Yes... make more sensors.

peak juniper
#

Defeats the point of the dynamic nature of the sensor, but I get your point. It's not possible.

ivory delta
#

Well the sensor isn't designed to be dynamic, you just want it to be. You could probably get clever using Grafana+Influx if you record the data for sensor.xbox_online there.

peak juniper
#

Yeah, that's a shame. I'll have a look into Grafana, etc.

ivory delta
#

You could always log a feature request on the forums for something that does what you're after. Or even make something if you have the skills - HA is open source.

brisk temple
#

can I wrap an or combined with a and {{ is_state('calendar.school_year', 'on') and (states.calendar.school_year.attributes.message | regex_search('break', ignorecase=true) or states.calendar.school_year.attributes.message | regex_search('holiday', ignorecase=true)) == true }}

#

template editor seems to be fine with it

ivory delta
#

Yes, combining boolean logic is valid syntax.

brisk temple
#

thx

celest wave
#

Hello folks,
Have a small question, may be someone can bring some lite for me.
Is it possible to pass variable in template states request ?
`- condition: template
value_template: "{{ states.sensor.VARIABLE.state == 'ON' }}"

  • condition: template
    value_template: "{{ states(sensor.VARIABLE) == 'ON' }}"`
brisk temple
#

there's no global variables, so you would have to define it elsewhere, an input_* usually is what people do

celest wave
#

The case here is to have single script which will be ran with passed variable and do the work based on these vars..

ivory delta
#

This appears to be in a script/automation, so you can use variables.

#

That's how to re-use variables within a script.

celest wave
#

Yep, I saw and read these docs, the main problem here is to use variables inside template in states request. I believe if I pass it as in code block above, it will not be taken as variable.

ivory delta
#

IIRC you have to get clever with how you build the states('sensor.sensor_name') part of the template.

#

What do you want to pass in as a variable?

celest wave
#

different sensors.. for example sensor.sensor1 , sensor.sensor2 , sensor.sensor3 etc..

ivory delta
#

How are you choosing what to pass in? Could you pass in the whole name (i.e. 'sensor.sensor1')?

#

Or are you only passing in 'sensor1'?

celest wave
#

Yes, actually I can pass 'sensor.sensor1' in variable.
Will it work in the way states('VARIABLE_value') ?

ivory delta
#

Close

#

If you're passing in the full string as the variable 'name', you should just be able to do "{{ states(name) == 'ON' }}"

#

You only quote strings. If you're using a variable, skip the quotes.

celest wave
#

I will try it, thank you! Sry if the question was stupid, I am newbie in HA. πŸ™‚

ivory delta
#

It's not stupid at all. One other thing... 'ON' is probably wrong. States are normally 'on'/'off'.

buoyant pine
#

Yep, everything is case sensitive

ivory delta
#

And you can test your templates using something like this (just change your sensor name, that's one of mine):

{% set name = 'binary_sensor.front_door_contact' %}
{{ states(name) == 'on' }}```
celest wave
#

ON is working in my case, it is came from my other device Megad2561 via mqtt

ivory delta
#

(in devtools > Templates )

#

Yep, everything is case sensitive
@buoyant pine Unless you do |lower on everything πŸ˜„

celest wave
#

I already understood that it is case sensitive and had some problem when saw 'On' in mqtt and it cannot be changed...
Resolved by: state_template: "{{ value_json.state|regex_replace(find='OFF', replace='off', ignorecase=False)|regex_replace(find='ON', replace='on', ignorecase=False) }}"
πŸ˜„

ivory delta
#

Oof... that's a long way to force lower case.

celest wave
#

Unless you do |lower on everything
Didn't know about it on those moment .. )

ivory delta
#

πŸ˜„

#

Jinja (the templating engine) has 'filters' for all the basic stuff.

buoyant pine
#

Heh, yeah | lower is the way to go

ivory delta
#

Don't use the lower() syntax, use the pipes (|lower).

celest wave
#

Saving this link right now )

ivory delta
#

Tediore - could you pin that link?

ivory delta
#

❀️

#

My first pinned message. I'm finally useful.

celest wave
#

Thanks guys! πŸ™‚

thorny snow
#

I've got a zwave sensor that spits out 22 or 23. I want to template it so it's more of a nice readable Open/Closed... but somehow I'm messing that simple process up. CAn anyone take a look at this and tell me what I'm doing wrong?

https://paste.ubuntu.com/p/zfX6Fqzwz8/

#

I've put it in my 'sensor:' section

ivory delta
#

{{ 'open' if is_state('sensor.guest_room_door_access_control', '22') else 'closed' }}

#

And remember things are case-sensitive. 'Closed' isn't the same as 'closed' for states.

thorny snow
#

Why would it matter here? aren't I just basically saying use the name Closed as output?

#

couldn't I call it anything I wanted?

ivory delta
#

For a sensor.

#

Follow conventions so they're predictable when you use them elsewhere.

#

If it was for the UI, you could call it what you want.

thorny snow
#

perhaps the UI is what I want...

ivory delta
#

But Lovelace won't know how to interpret 'Open'/'Closed' because they're not the right values for the state of an opening.

thorny snow
#

i guess i wasn't aware there was a difference

waxen rune
#

and for a door sensor you might want to use a binary_sensor like this:

    entredorr_tmpl:
      friendly_name: 'EntrΓ©dΓΆrr'
      device_class: door
      value_template: "{{ is_state('binary_sensor.entredorr', 'on') }}"
rugged laurel
#

If it's a templates binary sensor you can use device class

thorny snow
#

I thought about using a binary sensor, but when i looked at the doc, it looked like it was looking for certain values.. 22/23 was not them, even though to me, that seems like a binary value

ivory delta
#

Template binary can turn anything into an on/off type sensor.

thorny snow
#

ahhh ok

waxen rune
#

in my example it's in your case 22 "or else" and I think that's fine

thorny snow
#

This line threw me: These sensors only have two states: 0/off/low/closed/false and 1/on/high/open/true. K

ivory delta
#

Which is why I said about 'Closed' not being the same as 'closed'. HA's states are lower-cased.

#

Once you make a sensor with the right states, everything else will understand it.

thorny snow
#

That makes sense. I thought the area I put closed, I could put whatever I wanted the value to display

rugged laurel
#

Docs are "guidelines", you can do more than what's documented, if every possible use case was documented, it would be so much that you would never find anything

ivory delta
#

You could... but it wouldn't follow the same pattern as everything else.

thorny snow
#

I thought I could put "MIL LEFT THE DOOR OPEN!!!"

#

ok... i'll go back to the drawing board. Also, i noticed you all short handed the templates. Is there a tutorial on doing that? looks much easier

ivory delta
#

Like the others have said... you're basically making a binary sensor. Might as well use the right tool for the job.

thorny snow
#

I'll give that a go and see

#

ty

thorny snow
#

I tried switching the '22' -> 22 thinking it was something to do with the string vs int but that didn't do the trick

ivory delta
#

What was your config for the sensor in the end?

#

Or is that the binary sensor?

#

Because if it's a binary sensor, you need to understand this bit:

value_template template REQUIRED
The sensor is on if the template evaluates as True and off otherwise. The actual appearance in the frontend (Open/Closed, Detected/Clear etc) depends on the sensor’s device_class value

thorny snow
#

I moved it to the binary sensor section of my config and the code above is what I used.

#

so i need to change the open == on and closed to off?

#

making that change.

buoyant pine
#

No, the value template should just be "{{ is_state('sensor.guest_room_door_access_control', '22') }}"

#

The template needs to evaluate as True or False

thorny snow
#

How do I read that in human readable?

#

it will help me understand what it's doing

ivory delta
#

It just says 'is the state of sensor.guest... equal to 22?'

thorny snow
#

and thats a true/false yes/no answer

#

?

buoyant pine
#

Put that in the template tool at dev tools > template

ivory delta
#

'Is it 22?' only has two answers... yes or no πŸ™‚

#

That's what makes the binary sensor binary.

buoyant pine
#

binhairy sensor

thorny snow
#

I template very rarely (obviously) so I'm extremely green and confused on it.

ivory delta
#

Don't worry, binary stuff is tricky.

#

They say there are only 10 types of people. Those that understand it and those that do.

thorny snow
#

lol

#

So one additional question. That worked btw, but i've got other door sensors (non zwave) is there a way to template them all in a similar way? I like the way this one shows up in my lovelace

buoyant pine
#

There are two kinds of people: those who can extrapolate missing data

thorny snow
#

and???? /s

#

don't leave me hanging.

fossil hearth
#

the api give only temperature as value decimal

how to get that value using template ? πŸ™‚ this is a commnad line with curl get

#

Done thanks πŸ™‚

spare kernel
#

hi! Can someone help me about my problem? πŸ™‚

blazing burrow
#

when i try to use this template in the template editor:

{% set zipped = dict() %}
{% set options = state_attr('input_select.options', 'options') %}
{% for i in (range(1,3) | list) %}
  {% set key = options[i-1] %}
  {% if key in options %}
    {% set _ = zipped.update( {key: i} ) %}
  {% endif %}
{% endfor %}
{{ zipped }}

i get the error: SecurityError: access to attribute 'update' of 'dict' object is unsafe.

spare kernel
#

I have home thermostat which i set up with sonof R3 basic wifi and one reley, because i have radiators valves with temeprature senzors. So, the only way to have some kind off smart on/off thermostat is this way. When sonoff switch is on heating is off, ande when sonoff switch is off, heating is on. Sounds stupid but it works. So my question is ; I have made generic thermostat and pair it whit xiaomi sensor and sonof switch, but problem is state of switch..When I set desired temperature of 25 sonoff switch set to on and heating is off

blazing burrow
#

i'm trying to "zip" the list of options from an input_select with their respective indices

#

could anyone offer guidance? i had hoped i could do it with a dict comprehension, but it didn't quite work out as i'd hoped

rugged laurel
#

use namespace

blazing burrow
#

?

inner mesa
#

Variables defined/used inside a loop vanish once outside the loop

#

Namespaces fix that

fossil hearth
#
{"sensors":{"28-00000b988fef":"38.0","28-00000b98f5e6":"36.25","28-00000b9905e1":"40.375","28-00000b9920f3":"44.5","28-00000b994f64":"40.437","28-00000b9951c4":"36.812","28-00000b996c8c":"39.75","28-00000b99a737":"32.875","28-00000b99a884":"33.062","28-00000b99b4f0":"39.062","28-00000b99f29e":"37.812","28-00000b99fa3c":"34.062","28-00000b9a170e":"40.125","28-00000b9a1ca5":"41.562","28-00000b9a2529":"31.875","28-00000b9a3025":"42.062","28-00000b9a444d":"45.625","28-00000b9a4668":"46.125"}}

how to get the first sensors value ?

value_template: '{{ value_json["sensors"][0]["28-00000b988fef"] }}' Seems not to be working

ivory delta
#

{{ value_json.sensors["28-00000b988fef"] }}

#

There's no array in what you've shared, so you don't need to do [0] to get the first thing.

#

You just reference them by name instead.

#

You might also want to turn the result into a float (decimal number) instead of a string too:
{{ value_json.sensors["28-00000b988fef"] | float }}

ionic hazel
#

I have a template to turn on my TV, and another to turn on my AV Receiver. Can i combine them into one?

ivory delta
#

Templates that turn things on? What is this strange magic you speak of?

ionic hazel
#

yea i figured something was wrong as i was saying that

#

it's a switch and a template sensor

#

*value template

#
  - platform: template
    switches:
      denon_heos_music:
        friendly_name: Denon HEOS Music
        value_template: >
         {{ is_state_attr('media_player.denon_avr_x1500h', 'source', 'HEOS Music') }}
        turn_on:
         service: media_player.select_source
         data:
           entity_id: media_player.denon_avr_x1500h
           source: 'HEOS Music'
        turn_off:
         service: media_player.turn_off
         entity_id: media_player.denon_avr_x1500h```
#

not the same thing as a template then?

ivory delta
#

It makes use of templates. That doesn't make the whole thing a template.

ionic hazel
#

got it. thanks Mono!

fossil hearth
#

You might also want to turn the result into a float (decimal number) instead of a string too:
{{ value_json.sensors["28-00000b988fef"] | float }}
@ivory delta Did not work 😦

#
  - platform: command_line
    name: Ds1test
    command: "/usr/bin/curl curl -X GET http://192.168.40.210:8080/rest/api/v1.0/temperature "
    scan_interval: 3
    unit_of_measurement: C
    value_template: '{{ value_json.sensors["28-00000b988fef"] | float }}'
ivory delta
#

Use the Dev Tools to test it. devtools > Templates

#

You'll see there's an example like this:

{% set my_test_json = {
  "temperature": 25,
  "unit": "Β°C"
} %}```
fossil hearth
#

aha πŸ™‚

ivory delta
#

You can set your JSON there... and below that, experiment πŸ˜‰

fossil hearth
#

❀️

#

You can set your JSON there... and below that, experiment πŸ˜‰
@ivory delta am i doing it right

#
{% set my_test_json = {"sensors":{"28-00000b988fef":"42.312","28-00000b98f5e6":"51.937","28-00000b9905e1":"39.062","28-00000b9920f3":"39.062","28-00000b994f64":"37.625","28-00000b9951c4":"37.812","28-00000b996c8c":"38.0","28-00000b99a737":"33.687","28-00000b99a884":"33.25","28-00000b99b4f0":"38.937","28-00000b99f29e":"37.75","28-00000b99fa3c":"34.187","28-00000b9a170e":"36.562","28-00000b9a1ca5":"37.75","28-00000b9a2529":"32.375","28-00000b9a3025":"40.187","28-00000b9a444d":"42.125","28-00000b9a4668":"41.312"}} %}

The temperature is {{ value_json["sensors"]["28-00000b988fef"] }} {{ my_test_json.unit }}.

#

thanks πŸ™‚

ivory delta
#

That looks okay. Does it work for you?

fossil hearth
#

no 😦

ivory delta
#

Do it in small steps. Try {{ value_json.sensors }} and see what that shows.

fossil hearth
#

still nothing

ivory delta
#

Oh... don't use value_json... use my_test_json here πŸ™‚

#

Or rename my_test_json to value_json.

#

The name doesn't matter as long as they match.

#

This works for me:

{% set value_json = {"sensors":{"28-00000b988fef":"42.312","28-00000b98f5e6":"51.937","28-00000b9905e1":"39.062","28-00000b9920f3":"39.062","28-00000b994f64":"37.625","28-00000b9951c4":"37.812","28-00000b996c8c":"38.0","28-00000b99a737":"33.687","28-00000b99a884":"33.25","28-00000b99b4f0":"38.937","28-00000b99f29e":"37.75","28-00000b99fa3c":"34.187","28-00000b9a170e":"36.562","28-00000b9a1ca5":"37.75","28-00000b9a2529":"32.375","28-00000b9a3025":"40.187","28-00000b9a444d":"42.125","28-00000b9a4668":"41.312"}} %}

The temperature is {{ value_json["sensors"]["28-00000b988fef"] }}```
#

The temperature is 42.312

fossil hearth
#

Thank you soo much works for me

#

i will test it live

#

you are the best ❀️

#

my rockstar πŸ˜› hahaha

#

but when it comes to live its not working ... this is crazy ..

#
  - platform: command_line
    name: testingnow
    command: "/usr/bin/curl curl -X GET http://192.168.40.210:8080/rest/api/v1.0/temperature "
    scan_interval: 3
    unit_of_measurement: C
    value_template: '{{ value_json["sensors"]["28-00000b988fef"] }}'
#

the only reason why am using command-line is becase rest will exceed 255 characters

#

and i got this command working otehr places its a coppy paste and edit ..

ivory delta
#

I think you can use REST for long responses. You just can't set the state to something longer than 255 characters.

#

By default, the sensor state would be set to the full JSON β€” here, that would exceed the 255-character maximum allowed length for the state, so we override that default by using value_template to set a static value of OK.

blazing burrow
#

@inner mesa i guess i don't get how namespaces help? the template won't allow me to use update on a dict, which should be in scope

inner mesa
#

It’s not

#

Inside and outside the loop are different scopes

blazing burrow
#

ahh ok, lemme see

#

like this?

{% set ns = namespace(zipped={}) %}
{% set options = state_attr('input_select.options', 'options') %}
{% for i in (range(1,3) | list) %}
  {% set key = options[i-1] %}
  {% if key in options %}
    {% set _ = ns.zipped.update( {key: i} ) %}
  {% endif %}
{% endfor %}
{{ ns.zipped }}
inner mesa
#

I believe so. Does it work?

blazing burrow
#

no

#

i get the same error

#

i'm apparently not allowed to use update

inner mesa
#

Same with options

blazing burrow
#

oof, oh yeah

inner mesa
#

That’s could be

#

There are some jinja restrictions

blazing burrow
#
{% set ns = namespace(zipped={}, options=state_attr('input_select.options', 'options')) %}
{% for i in (range(1,3) | list) %}
  {% set key = ns.options[i-1] %}
  {% if key in ns.options %}
    {% set _ = ns.zipped.update( {key: i} ) %}
  {% endif %}
{% endfor %}
{{ ns.zipped }}
#

same error here, but removing the ns. on line 4 actually does render

#

it renders {}

#

actually it renders if i remove the one on line 5 too

inner mesa
#

That set line in the loop looks wrong

rugged laurel
#

You are not allowed to use update

blazing burrow
#

i thought so too?

rugged laurel
#

We are running sandbox

blazing burrow
#

i think i need to do something like ns.zipped[key] = i?

rugged laurel
#

allowing update, would mean you would acually update the state objects

blazing burrow
#

wait what? ns.zipped in my template is a dict i create and populate

#

so there isn't really a way to do this then?

#

for example, if my input_select has ['A', 'B', 'C'], i want to end up with something that has {'A': 1, 'B': 2, 'C': 3}

rugged laurel
#

You can change the ns elements inside the loop

blazing burrow
#

... is that not what the template above attempts to do?

#

i have that

{{ state_attr('input_select.options', 'options') }}
{{ range(1,4) | list }}

gives me

['A', 'B', 'C']
[1, 2, 3]
#

so now want to zip those together

#

in python it's zip(list1, list2), done lol

wooden tangle
#

hey just wondering if someone could help me getting the cost for electric usage? please

wooden tangle
#

yes i did

inner mesa
#

it's just an extremely vague question

wooden tangle
#

i have code in the yaml but its not adding up

silent barnBOT
ivory delta
#

Our crystal balls are in for repair.

#

(damaged through overuse)

inner mesa
#

answer could be "visit website of power provider"

wooden tangle
ivory delta
#

So you're getting something from it. It's working.

#

What's wrong?

wooden tangle
#

yea but right now i only got a ps4 plugged into it

#

so cant be that much

#

only flashed the plug an hour ago

inner mesa
#

did you manually do the math?

ivory delta
#

||nope||

wooden tangle
#

yes i did but i tried to use it but didnt do much

warm isle
#

2 things could be happening

  • energy meter not calibrated
  • energy cost is off
ivory delta
#

Explain the math you want to use.

#

And explain why you think the HA sensor is wrong.

#

You're not giving us much information here, so we can't tell you what's wrong.

warm isle
#

7€/h playing ps4 🀣
uffff

wooden tangle
#

2 things could be happening

  • energy meter not calibrated
  • energy cost is off
    @warm isle ill try the first one now
#

54w /1000 then * .136 right

ivory delta
#

13.6c / kWh?

wooden tangle
#

yea

ivory delta
#

So... where's your kWh? I only see W and €

wooden tangle
#

sorry its here

ivory delta
#

You need to give us all the information. Don't just give small pieces...

#

Anyway, I'm outta here. Good luck.

wooden tangle
#

ok

warm isle
#

my guess now is that you use the watage instead of kwh for calculating prices

wooden tangle
#

so i can use the total kwh?

warm isle
#

uuuuuuhhhmmmmm
How would you otherwise calculate € out of it

wooden tangle
#

yea true

#

but im already using it in that code

warm isle
#

templates
what does "{{ (states('sensor.charger_hourly') }}" give you

#

http://<<ip or url>>/developer-tools/template

wooden tangle
#

gives me 0.01

warm isle
#

odd.. and the full
{{ (states('sensor.charger_hourly') | float * 0.136) | round(2) }}"

wooden tangle
#

0.0014

inner mesa
#

that makes no sense

warm isle
#

that looks right, but why you get 7.75 ? restarted while there

wooden tangle
#

1 sec

#

0.0

#

my bad

ivory delta
#

(pssst... current hour)

inner mesa
#

that's the |round(2)

warm isle
#

yea, set back the round to 4

ivory delta
#

This conversation started before the hour. Things have changed.

wooden tangle
#

yes but the cost is not right

#

defo not €7 per hour on a ps4

warm isle
#

your template tells you 0.0014
so thats right, restart ha and look if the numbers changing

#

youmaybe looking at the wrong sensor

wooden tangle
#

yea the usage looks right just not the cost

#

i only have one

#

ill restart it

warm isle
#

dont forget to press the check config button

wooden tangle
#

will do

warm isle
#

is this still a thing btw? back in the days with hassbian it was a terrible thing when you just restarted πŸ˜„

buoyant pine
#

Template sensors can be hot reloaded now

warm isle
#

not taking changes now πŸ˜›

wooden tangle
#

sorry im back now

#

daily is €39

#

hour is 0.0041

ivory delta
#

Spoiler alert... the current config is right but you didn't tell us about all the changes you made in the previous hour.

#

The sensor has a history. It still has the 'wrong' data from before you changed it.

wooden tangle
#

is there a way to clear the history?

ivory delta
#

Delete your database.

#

And this is why providing all of the information in the first place is so important.

#

Several people were trying to troubleshoot a non-issue.

warm isle
#

@blazing burrow how is your isue going?
not that I'm able to help, but intrested if you where able to solfe it

blazing burrow
#

no, i moved onto something else for a bit

warm isle
#

Would 'need' something simalar for a telegram bot, one of the many abandoned things

blazing burrow
#

?

#

oh, i see what you mean

#

sorry

wooden tangle
#

db deleted and restarted,same values still there

warm isle
#

mapping a short value to a longer value

#

np

blazing burrow
#

mine is for mapping named options in an input_select to integers to send to wled api

#

i have a reasonable solution already, just looking for something cleaner/more general

warm isle
#

aah I know these stuggles

blazing burrow
#

lol

warm isle
#

feel free to ping me when you got it, interested:)

blazing burrow
#

πŸ‘

warm isle
#

.away zZzzZZz late in πŸ‡¦πŸ‡Ή

silent barnBOT
#

Underknowledge is away! zZzzZZz late in πŸ‡¦πŸ‡Ή :wave:

blazing burrow
#

i could do it in a second in python, in like a bunch of different ways πŸ˜…

inner mesa
#

<6 hours later> Success! I finally have it working exactly as well as it worked 6 hours ago!

blazing burrow
#

victory! lol

waxen rune
#

@wooden tangle Just curious, did you solve it?

wooden tangle
#

just managed to reset the values just now

#

so ill see how i get on

waxen rune
#

I noticed you have configured utility meters, does they work as expected?

wooden tangle
#

for the usage yes but not the cost

waxen rune
#

ok, I haven't followed everything here, but if you put {{ states('sensor.charger_daily') | float }} into dev tools, what's the response?

#

that seemed to be the utility meter, right?

wooden tangle
#

0.01

waxen rune
#

{{ ((states('sensor.tumble_dryer_total_daily_energy') | float) * 10) }}

#

just want to make sure here..

#

sorry

wooden tangle
#

np

waxen rune
#

{{ ((states('sensor.charger_daily') | float) * 10) }}

wooden tangle
#

0.1

waxen rune
#

ok, and finally {{ ((states('sensor.charger_daily') | float) * 0.14) | round(2) }} where you replace 0.14 with your price per kwh

wooden tangle
#

0.0

waxen rune
#

there it is πŸ™‚ no cost so far today

#

remove the round and take it * 1000 just to see it works

wooden tangle
#

okay thank you but ill keep an eye on it

waxen rune
#

..or try the {{ ((states('sensor.charger_monthly') | float) * 0.14) | round(2) }} , I guess the monthly have a value a bit higher still?

wooden tangle
#

0.0 because i just reset it all

waxen rune
#

oh

wooden tangle
#

it had the history of previous mistakes but ill leave it now and see

waxen rune
#

if you take it * 10000 instead of you price, you should see results pretty soon

ivory delta
#

No

#

Don't introduce bad data to his history again.

waxen rune
#

no?

ivory delta
#

It's working, just leave it.

#

It was working before the discussion even began,.

#

At some point before Galaxy started asking for help, they'd already had the right configuration. They just gave poor information.

wooden tangle
#

might just go and boil the kettle πŸ˜‚ , yea kinda just had to reset i guess

waxen rune
#

just a note: but when I said "take it * 10000 instead of you price, you should see results pretty soon", I meant in dev tools, that can hardly introduce bad data again?

#

or am I missing something more here?

ivory delta
#

A little, yes. The templates that Galaxy shared were good. No apparent problems with how they looked and they gave all the right results in dev tools.

#

The only problem is that before they asked for help, they must have already tried incorrect templates on their live sensors. Their database had bad history, so they thought there was a problem still.

wooden tangle
#

i appreciate the help from the 3 of you guys, hopefully it will be fine from here on out.

#

and yea it was that and trying maths equations too

#

looks good so far

#

just used the kettle to boost it

blazing cobalt
#

Hi everyone! I'm trying to make an automation to set the time value of an input_datetime entity to the next hour (eg. if the current time is 15:19 set the time value to 16:00). Am using the automation editor, have set up the trigger and the action (call service input_datetime.set_datetime), it's just the template stuff for the service data that I'm having trouble figuring out. I think I want to pull the hour from states('sensor.time') and add one to it (watching out for the case around midnight where it needs to go back to zero), and then express that as a time in the correct format for the service to understand, but I'm not sure how to do that - or if there's a more elegant way?

lyric comet
#

I am new to HA but I wonder if something like this would work
{{((as_timestamp(now()) + (59 * 60 + 59))) | timestamp_custom('%Y/%m/%d %H:00:00 ')}}
So it adds an hour less one second and then you have the year,month and hour and just set the minutes and seconds to zero.

blazing cobalt
#

Thank you, sounds like it could work. I don't need the date, just the time, but I can leave those bits out. I'm not quite sure how to put it into the automation editor in the right way for it to understand it either, I'm pretty new to this too

#

Ok getting there with that part at least

lyric comet
#

Google suggests that you can not template the setting of the value on an input entity and I can't get the developer tools to let me, what were you going to the use the field for. You could use a time trigger directly if you just want to trigger something on the hour.

ivory delta
#

You don't use the template to set something. You use the template as part of something.

#

It's valid to pass a template as the argument to a service. Its value will be evaluated and passed to the service.

#

Example:

action:
  service: "homeassistant.turn_{{ trigger.to_state.state }}"
  data:
    entity_id: group.landing_switches```
blazing cobalt
#

Ok thanks, so I know I can set the service data to time: '{{template}}' - I just need to figure out the template

#

Also some stuff from google led me to believe that now() isn't necessarily up to date and I should use sensor.time

ivory delta
#

It used to be that now didn't update templates. I think that may have changed.

#

You'll find out if you test your templates in the Dev Tools. It has a hint under the right hand side to say what will trigger re-evaluation.

blazing cobalt
#

Oh ok, that's useful thanks

#

This template does not listen for any state changed events and will not update automatically.

inner mesa
ivory delta
#

The 'will not update automatically' is a little misleading πŸ˜„

#

It's just less frequent. If once per minute is good enough for your use case, stick with now().

#

And that only matters for triggers anyway. If you're using it in an action, it'll evaluate on demand.

blazing cobalt
#

Oh ok that's great then, thanks - now() will be fine

inner mesa
#

sorry, should have been clearer about what was correct πŸ™‚

blazing cobalt
#

All good, thank you πŸ™‚

#

Using @lyric comet 's original suggestion, this seems to work now: time: '{{ ((as_timestamp(now()) + (59 * 60 + 59))) | timestamp_custom("%H:00") }}'

#

Tho I don't know what happens around midnight

ivory delta
#

You can test it in the Dev Tools and find out

blazing cobalt
#

Ok I remembered about modulus, and I decided to try another approach, now I seem to have got the hang of formatting it. Now I've got time: '{{ (now().hour + 1) % 24 }}:00'

#

Test run seems to work, gonna see what happens in 5 minutes

ivory delta
#

Oh, that's a nice approach 😻

blazing cobalt
#

Woop seems to be working!

#

Thank you all for your help, much appreciated πŸ™‚

ivory delta
#

You did the work in the end πŸ˜‰

thorny snow
#

Hi!
I am trying to get sensor data from a string, which looks like this:

data:

  • datetime: '2020-11-15T16:00:00.000Z'
    value: cloudy
  • datetime: '2020-11-15T17:00:00.000Z'
    value: rainy

I am trying to make a sensor, which grabs the weather conditions at particular times for today and tomorrow. Im not a programmer and Ive been trying to get the data but i have not succeeded.. can anyone help me on my way?

fossil hearth
#

HI πŸ™‚ how to make this work ? {% if value_json.getitem('404 Not Found')) %} ?
i wanne check if value_jason contain that

mighty ledge
#

@fossil hearth {% if value_json[β€˜404 Not Found’] %}

#

{% if β€œ404 Not Found” in value_json %}

fossil hearth
#

invalid template ..

silent barnBOT
fossil hearth
#

all gd i just had to restart it

fossil hearth
#

@fossil hearth you need to wrap it in quotes. or use multiline notation. Also, that code requires that CustomUI is installed.

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

@mighty ledge installed the custom UI sucsefully but still not working ? do i need to add a command somhwere ?

thorny snow
#

Hi everyone, I am looking for a way to perform an action on several entities based on a regex on their names.

#

I'd like to run a loop like that : {% for entity_id in all_entities | regex_match("switch.schedule_*") %}

#

to perform the action on all my switch.schedule_*

#

These entities are generated directly through a card, from the UI, so I do not really know how many there is and this can change during the run

#

But I'd like an input_boolean to deactive/active all.

wraith shell
#

@waxen rune thanks a lot, that's a great idea!

waxen rune
#

Don't know what you mean, but I'm glad to help πŸ™‚

mighty ledge
#

@fossil hearth clear your cache and reload the page

sinful bison
#

Hi :)
does anyone have a way to use this as a trigger
"{{ expand('group.battery') | map(attribute='state') | map('int') | select('lt', 15)|list |count > 0 }}"
but have it ignore 'unavailable' state ?

#

map(attribute='state', default="100") don't work because 'unavailable' is a value

#

well i didn't think hard enough 🀦 I've been on this for week, but just now think about map('replace', 'unavailable', '100')

desert crane
#

thoughts on how to elegantly add trigger.for into else portion of
switch.turn_{{ 'off' if trigger.to_state.state == 'home' else 'on' }}
too screwy for oneliner?

charred dagger
#

What do you want it to do?

desert crane
#

it being instant on home value and wait for x minutes for else value

buoyant pine
#

What does your trigger look like?

desert crane
#

so we are looking at any state change

buoyant pine
#

Yep, I've gotcha

desert crane
#

dont want to make multile automations and keep it clean if possible πŸ™‚ things must wait when i leave but not keep me in dark-cold for x minutes when i return

buoyant pine
#

So do you just care about home/not_home with this automation?

desert crane
#

thats what it does yeah, just want to modify the else 'on' into else trigger.for 10 minutes ... 'on'

buoyant pine
desert crane
#

ok

amber zodiac
arctic sorrel
#

I didn't say that'd solve that problem

amber zodiac
#

What does it do then? How does it help?

#

What does it do in teaching to fish?

arctic sorrel
#
    action:
      service: persistent_notification.create
      data:
        title: "New HA Podcast available"
        message: "New Podcast available - {{ as_timestamp(now()) | timestamp_custom('%I:%M:%S %p %d%b%Y', true) }}"
        notification_id: "{{ trigger.event.data.title }}"
#

trigger.event.data contains information about the new entry, the docs show that at least title and content exist

#

Also says:

Any field under the <entry> tag in the feed can be used for example trigger.event.data.content will get the body of the feed entry.

#

So, you can use similar logic for anything else in that tag

amber zodiac
#

I have looked at all examples... no example is about differentiating triggers from different URL feeds. How does trigger.event.data help me differentiating content from different feeds? That would be different for all feed URLs every single time a new feed gets published in rss.

I dont think you are even reading my problem than spamming me to read the same link (and earlier devices link which seems nothing to do with my query)

arctic sorrel
#

Good news, we're all volunteers here. I don't have to help you, and I'm done here

amber zodiac
#

And btw "trigger.event.data.content" is broken. It doesn't work. No feed content gets fetched. Do I need to open github issue for that?

#

Ok thanks very much. So much for slamming new users to every channel and posting unrelated links than understanding the query. And then giving lecture on "teaching to fish " , even if someone tries

buoyant pine
#

Dude, this is free help. No one is obligated to help at all and there's no guarantee any help you receive will fix the problem. Sorry if it's not up to your standards, maybe you can apply for a refund

amber zodiac
#

Yeah may be "volunteers " stop ranting that they are teaching to fish and the other person should try. When the other person does try and make something work, all they do is posting same links which have nothing related to next related query.
And then its easy to say " I dont know if it works or not or even related . Its free help. I am a mod. I can misguide new users without any responsibility and spam them to various channels for related questions "
Right ? Wow

arctic sorrel
#

🀣

#

You ain't seen me rant... and I've posted you at the relevant links to the questions you've posted.

#

Also, no, I don't know how to do everything. There's 1713 integrations. I don't use all of them, nobody does.

buoyant pine
#

None of us here are trying to misguide users or "spam them to various channels"

#

There are channels for a reason. People who help look at specific channels

arctic sorrel
#

Turns out that my answer above is right though, it will work with the right tag in trigger.event.data

amber zodiac
#

Yeah making large emojis helps. Nice. Speaks loud of how responsible you are as a volunteer (mod) .. lol

ivory delta
#

Well that looked fun πŸ˜„

surreal stratus
#

Can someone help me getting my solar template to work

#

SENSOR.YAML

sensor:

  • platform: template
    sensors:
    #This is converting the Solar Energy to KWH#
    solaredge_energy_today_kwh:
    friendly_name: 'Solar Today'
    unit_of_measurement: 'kWh'
    value_template: "{{ (states('sensor.solaredge_energy_today') | float / 1000) | round(2) }}"
#

This is in my Config.YAML

inner mesa
#

?

surreal stratus
#

I have solar panels and want to get the information to the dashboard. I did my googles and it told me to create a template for the sensor

#

its all very confusing

inner mesa
#

What is wrong?

surreal stratus
#

When I add this information to my config file. I thought I should get a new entity called "solaredge_energy_today_kwh"

#

but i dont seem to get anything. I might be all wrong in how this works tho

thorny snow
#

How do you get these informations Pixels ? You get some solar panel but what's giving you the production metrics ?

surreal stratus
#

The inverter

#

@thorny snow

inner mesa
#

You mention both sensor.yaml and β€˜config.yaml’ Where did you put that?

surreal stratus
#

@inner mesa i put the info above in my config.yaml

#

I dont have a seperate senor.yaml file

inner mesa
#

Why did you mention sensor.yaml?

#

Anyway, did you check your config?

surreal stratus
#

it was a comment to myself to keep a bit organized in the config yaml

silent barnBOT
#

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

inner mesa
#

Ok, that’s gonna be confusing

thorny snow
#

Ok; I have a bunch of small inverter thats why I do not have the same setup. On my side I am using an ESPhome integration.

#

How do you request your inverter ?

surreal stratus
#

I used the HACS they have a solaredge add on

#

I entered my site ID and it was able to pull up all the info

inner mesa
#

You didn’t format your code, so it’s hard to know whether it’s correct...

surreal stratus
#

Would a screencap be better?

inner mesa
#

No

surreal stratus
#

How to formate my code?

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

surreal stratus
#

'''

silent barnBOT
thorny snow
#

yep, before and after the code section πŸ˜‰

inner mesa
#

Sigh

surreal stratus
#

Sorry, did i do that correct?

thorny snow
#

yes

ivory delta
#

No codewalls please.

arctic sorrel
#

~codewall @surreal stratus πŸ˜‰

silent barnBOT
#

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

thorny snow
#

Hum, I'm not a jinja killer, but (states('sensor.solaredge_energy_today') | float / 1000) | round(2) shouldn't it be ((states('sensor.solaredge_energy_today') | float) / 1000) | round(2) ?

#

How do you test it ?

surreal stratus
#

I tested in the template tab

inner mesa
#

That should be okay as-is

surreal stratus
#

That should be okay as-is
@inner mesa okay. should I get a separate entity?

silent barnBOT
#

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

surreal stratus
#

Check shows up as green

waxen rune
#

have you restarted or reloaded the templates?

surreal stratus
#

I have. I get a log error saying that the sensor took too long to respond

#

Should I do something for it to show up in the front end?

inner mesa
#

it doesn't sound like you ran the config check

waxen rune
#

I'm curious if there is a problem with the template (which seems fine to me) or with the actual sensor sensor.solaredge_energy_today

surreal stratus
#

it doesn't sound like you ran the config check
@inner mesa I thought the green check box thingy was the check. Going back to google to get more info

inner mesa
#

no, I've posted the bot message twice now

surreal stratus
#

oh ok! i see it

#

doing it now

#

sorry suppppperrr new to this. Still trying to get my bearings

inner mesa
#

I think the bot messages are invisible to new HA users πŸ™‚

thorny snow
#

Is there a way to perform an action on all entities matching a pattern ?

inner mesa
#

depends on what that action is

surreal stratus
#

2020-11-16 11:49:53 WARNING (MainThread) [homeassistant.components.sensor] Updating solaredge sensor took longer than the scheduled update interval 0:00:30

#

Could this be because im using Duck DNS and not on my home network

thorny snow
#

I am using a card which is creating some switch, everyone can create several ones. I would like a "super button", so an input_boolean to set all of them off or on.

inner mesa
thorny snow
#

I was thinking about doing something like :

{% for entity_id in all_entities |  regex_match("switch.schedule_*")  %}
{{- entity_id }}                                                                                                 
{% endfor %}  
inner mesa
#

I don't think I could make that format work

#

it's the right idea, but comma-separated worked for me

thorny snow
#

Thanks a lot RobC !!

#

Seems doing exactly what I was looking for

wooden tangle
#

whats an other way to reset entity history. i tried deleting the db but its still there

mighty ledge
#

@wooden tangle you can only delete the history if home assistant is off.

#

@thorny snow

{% set ns = namespace(entities=[]) %}
{% for s in states.switch if s.object_id.startswith('schedule_') %}
{% set ns.entities = ns.entities + [ s.entity_id ] %}
{% endfor %}
{{ ns.entities | join(', ') }}
thorny snow
#

petro; ns is for generating a var with all entities ?

mighty ledge
#

namespace allows you to create a variable that persists across for loops

#

i created the variable 'entities' inside the namespace named ns

#

so to access, you use ns.entities

thorny snow
#

ok, got it, but I think I do not need to create this var. Thanks a lot for this I did not known

#

states.switch seems contains everything I need

mighty ledge
#

are you going to add more switches?

#

if so, you'll probably want to use the template.

#

otherwise you'll shoot yourself in the foot when you add another switch

thorny snow
#

Yes I'll add more switches, thats the point otherwise I could have done it without templates :/

mighty ledge
#

Then you'll want to use the template

thorny snow
#

yep

#

I tested it and it works well, (without ns part, since there is a fault with the ',')

mighty ledge
#

You may run into problems if you have an extra comma at the end

#

that's why I went with NS

thorny snow
#

ok

wooden tangle
#

so as in turn it off then on or off for abit

mighty ledge
#

with NS, you can just simply join the list together with commas

#

Turn off home assistant. Delete database. Turn on Home assistant.

#

this will require you to use SSH

thorny snow
#

ok, I was doing it with {%- if not loop.last %},{%endif%}

#

So I am doing the check with : {%- if not loop.last %},{%endif%}

#

sorry wrong paste : {% for i in states.switch if i.object_id.startswith('schedule') %}

#

which check if entity_id is starting with schedule; this is almost what I need: I would liked to check friendly_name. So if object_id is entity_id, what is friendly_name ? πŸ˜‚

#

🀞 I hope I can adress it from there ....

wooden tangle
#

just done it and nothing changed strangely

thorny snow
#

I cannot find what is the name of the dict entry to get the friendly_name .... What is i here ? a state objects ?

#

What does return states.switch ?

inner mesa
#

it's an attribute

#

this spits out the friendly names for me:

#
  {%- for i in states.switch if i.object_id.startswith('fr_') -%}
    {{ i.attributes.friendly_name }}
  {%- endfor %}
thorny snow
#

My switch is entity_id is switch.schedule_68da99 and when having a look on developper tab; it has : friendly_name: schedule_bed2_weekend

#

so it is its friendly_name; this switch has been generated by scheduler_card; this have set the optional friendly_name

inner mesa
#

ok

thorny snow
#

Is there a way to list content of states dict ?

inner mesa
#

all the attributes?

thorny snow
#

yes

#

a way to "debug" it, list all attributes or print the whole dict

inner mesa
#

{{ states.switch.fr_wallmote_switch.attributes }}

thorny snow
#

I'm tired about blind shots ^^ I need lights ...

inner mesa
#

{'node_id': 36, 'friendly_name': 'FR Wallmote Duo Switch'}

thorny snow
#

Here I would liked to search "FR 3 in your example ^^

#

i.friendly_name.startswith('FR ')

inner mesa
#

again, it's an attribute

#

althought i.name will evaluate to friendly_name if it's set

thorny snow
#

But you gives me * {{ states.switch.fr_wallmote_switch.attributes }} * which seems good, but where can I set it and see he result ?

inner mesa
#

devtools -> Templates

#

sorry, thought you were aware of that πŸ™‚

thorny snow
#

WOW Big thank !

inner mesa
#

so you were just guessing?

#

I see how that's challenging πŸ™‚

thorny snow
#

Amazing ... The french translation for template is "modèle" which can be quite good but in this context I never understood this tab ^^

inner mesa
#

you can type whatever you want there and it evaluates in real-time

thorny snow
#

I though it was to generate some text to make some "strange" reports

#

this tool will definitively help me so much

#

thanks for turning this light on ^^

mighty ledge
#

@thorny snow object_id is the object_id. entity_id = domain.object_id. So for switch.laundry, the domain is switch, the object_id is laundry, and the entity_id is switch.laundry.

#

to get the friendly name off the states object, it's simply just .name instead of .object_id

thorny snow
#

So it should be that : {% for i in states.switch if i.name.startswith('schedule') %}, isn't it ?

mighty ledge
#

if you use i as the states object, yes.

#

you can also get the friendly name through the attributes

#

i.attributes.friendly_name

thorny snow
#

When I'm doing it in the dev tool I got the right value : switch.schedule_68da99=schedule_bed2_weekend

#

But When I set it into my automation template with this if ... I get this issue

mighty ledge
#

what are you using in the dev tools?

thorny snow
#

voluptuous.error.MultipleInvalid: not a valid value for dictionary value @ data['entity_id']

#

In the dev tools (template tab πŸ˜‰ @inner mesa ) it works as you described

mighty ledge
#

post your configuration in the automation and post what you're putting in dev tools

thorny snow
#
- alias: Start/stop chambre enfant schedule
  trigger:
    platform: state
    entity_id: input_boolean.bed2_schedule
  action:
    data:
      entity_id: >-
        {% for i in states.switch if i.name.startswith('schedule') %}
         - {{ i.entity_id }}
        {% endfor %}
    service_template: switch.turn_{{ trigger.to_state.state | lower }}
mighty ledge
#

yes, as I said before that won't work

#

you cannot use a dash, at all.

thorny snow
#

yes you're right, but I did not yet understood why ^^

#

How yep thx, I mixed up the configs

mighty ledge
#

this is because the entity_id field accepts a list or a single value

thorny snow
#

got it

mighty ledge
#

a listed item is denoted with a dash (-) in yaml, but templates only output single values

inner mesa
#

didn't that change in 0.117?

#

yet it still didn't work when I tried it earlier

#

that was during the 0.117 beta

thorny snow
#

It works !

#

Thanks a lot guys

#

My final syntax is the following

#

fg

inner mesa
#

and that's why I mentioned the comma-separated version

dreamy sinew
#

with the new template stuffs you can output a list object and that'll work

thorny snow
#
- alias: Start/stop chambre enfant schedule
  trigger:
    platform: state
    entity_id: input_boolean.bed2_schedule
  action:
    data:
      entity_id: >-
        {%- for i in states.switch if i.name.startswith('schedule') -%}
        {{ i.entity_id }}
        {%- if not loop.last %},{%endif%}
        {%- endfor %}
    service_template: switch.turn_{{ trigger.to_state.state | lower }}
inner mesa
#

you just want service: there, not service_template:

thorny snow
#

What's teh difference .... I was thinking I was needing it as soon as I was using some jj2 ...

inner mesa
#

the _template version of service and data were deprecated back in 0.115

#

it's probably showing a warning now

#

you don't need them anymore - templates are always accepted in data: and service: blocks

thorny snow
#

ok, thanks

dreamy sinew
#
{%- for i in states.switch if i.name.startswith('schedule') -%}
{% set ns.switches = ns.switches + [ i.entity_id ] %}
{%- endfor %}
# with new stuff
{{ ns.switches }}
# old method
{{ ", ".join(ns.switches) }}```
inner mesa
#

looks like more characters

mighty ledge
#

I already posted that solution a while ago but he didn't want it

inner mesa
#

it's the same thing

dreamy sinew
#

lol yup

inner mesa
#

it has the same result as what I posted

thorny snow
#

nope petro; you posted : {{ ns.entities | join(', ') }}

dreamy sinew
#

same thing

mighty ledge
#

yep

thorny snow
#

and this gaves me a syntax issue and since RobC posted before the {%- if not loop.last %},{%endif%}, (that I am usually using in ansible) I used his syntax

mighty ledge
#

@inner mesa in .117 you don't need to join the list with commas, but I'm not sure if it will work because thats a special case

inner mesa
#

really? didn't know that

#

so a space-separate list is accepted?

mighty ledge
#

entities has always been a special case. We pass a comma separated string to entities and it works. It's the only field where a comma separated list will work

#

otherwise you'll need a 'real' list object or a single item

thorny snow
#

But I keep in mind your syntax about namespace, it will help me I think πŸ˜‰

inner mesa
#

I noticed that when I tried to create a list of states

mighty ledge
#

yeah it's an oddball for sure

#

for the most part, this will work now as @dreamy sinew said:

{% set ns = namespace(switches=[]) %}
{%- for i in states.switch if i.name.startswith('schedule') -%}
{% set ns.switches = ns.switches + [ i.entity_id ] %}
{%- endfor %}
{{ ns.switches }}
inner mesa
#

the fact that it can live outside of data:, but with reduced functionality is also weird. but less typing, I guess.

mighty ledge
#

what do you mean?

dreamy sinew
#

that will output a list

inner mesa
#

entity_id: can live both inside and outside data:

mighty ledge
#

@dreamy sinew yah 117 and 118 should accept that now

inner mesa
#

but outside of data:, you can't use templates

mighty ledge
#

Ah yes, that's also a caveat

dreamy sinew
#

i think inside data was a workaround for that reason

#

and no one went back to deprecate out the outside one

mighty ledge
#

yep

#

I don't think it'll ever get deprecated

#

it's used too much

dreamy sinew
#

yeah, definitely not now

mighty ledge
#

and it's nice for shorthand

thorny snow
#

Is there some logs on this deprecation ?

#

Because I did not saw anything ....

dreamy sinew
#

it isn't and won't

inner mesa
#

you mean the _template: variants?

dreamy sinew
#

oh

inner mesa
#

I thought it did spit out a warning, unless it changed

#

I've seen people ask/complain about it

#

looks like it's just a tooltip in VSCode

dire flare
#

I'm just now diving into templates finally (like three years later) - I'm trying to create a sensor to pull the temperature attribute out of the weather.home component does anyone have like a good baby step to get my feet yet

#

because I already messed it up trying to add it to my sensors.yaml lol

mighty ledge
#

use the template editor in dev tools

dire flare
#

yeeeet

#

thank you

#

That helped - I got the temperature to pull out correctly now I know it's in my sensor.yaml file I'll keep pecking away thanks!

#

Go figure... it was my indentation again I mentioned in the automation channels lol

#

IT WORKED THANKS @mighty ledge wooooooo

#

Now I can run my freeze protection on the pool using the weather card data instead of a thermometer I have in the ground lol

mighty ledge
#

@dire flare Is the sensor you have in the ground bad? I feel like I would trust that over the weather 🀣

arctic sorrel
#
        {{ -3 < ((as_timestamp(now()) - as_timestamp(states.image_processing.doods_front_camera_snapshot.last_updated)) < 2 ) }}

is basically

{{ -3 < MAGIC < 2 }}
#

It'll return true if MAGIC is between -3 and 2

#

Go and drop ```
{{ as_timestamp(now()) }}

limpid anvil
#

So...

#

Start of each minute

arctic sorrel
#

What is?

limpid anvil
#

When I put {{ as_timestamp(now()) }} in developers, I get a string with explanation updates the start of each minute

ivory delta
#

You don't care about how often it updates, you care about what it represents.

#

It's a timestamp that represents 'now'.

limpid anvil
#

I'm guessing your template means... if processing is from now between -3 and under 2, proceed?

arctic sorrel
#

The number is a value in seconds

ivory delta
#

The time is in 'seconds since the beginning of 1970'.

arctic sorrel
#

All that template does is make sure that the entity has just updated

limpid anvil
#

Yes, I want to adjust it, because I get notified with your script. It shows me There was motion at the front at 2020-11-16 21:16:01.
We saw nothing of importance.. While I see the current camera snapshot and processed image attached

#

I'm guessing it's being processed too quick because I'm using tflite model

arctic sorrel
#

Well, you've two things to check:

  1. That the image_processing entity has information
  2. That the monster script produces output that's got "interesting" things
limpid anvil
#

I don't really understand the interesting things input number either πŸ˜›

arctic sorrel
#

You're trying to fly before you've worked out to crawl

limpid anvil
#

You are absolutely right!

arctic sorrel
#

Get Doods producing useful output

#

Until you get that working, don't do anything else

limpid anvil
#

Tensorflow models are processing way too long

#

I'll try more troubleshooting. Not sure what direction to look at

#

I've reduced the resolution of my main camera stream and made sure cpu usage is minimum... Yet doods comes and uses every % of CPU, and causing delay.

arctic sorrel
#

To be expected on your hardware