#templates-archived

1 messages Β· Page 10 of 1

versed lava
#

and for two phone numbers, I'd just add a second variable and a second sensor, right?

marble jackal
#

Yes, you can use the same trigger

#

I'm off to bed now, good luck

versed lava
#

thank you a lot!!!

tepid onyx
#

Thanks Fes,
I thought about concatenation too but the parser really doesn't like the asterisk at the beginning...

#

If I remove it, no problem

#

maybe regex replace

sage stirrup
#

beginner looking for some help building a script

versed lava
sage stirrup
#

Is there anyone around that would be willing to walk me through building an automation/script using a template that is probably not that complicated?

#

I have a button, when pressed starts an automation. I want the automation to grab the value of a field, and then add that value to a counter. I'm using the template developer and figured out how to get the value of the numerical field,.... but.. I can't figure out how to add that value to a counter.

#

I can add the increment counter service to the automation but it only adds one increment instead of a specific number of increments

#

Basically I got a value in a numerical field. when I push the button I want to take that number and add it to another field.. I gues it doesn't have to be a counter?

inner mesa
#

seems like a counter maybe isn't what you want

sage stirrup
#

Ah ok

inner mesa
#

sounds like a job for an input_number

sage stirrup
#

Thanks.

#

If I have a value how would I add it to an existing input_number?

I have the value in this string:

{{ (states('input_number.minutes_to_add') | float) + (states('input_number.hours_to_add') | float * 60) }}

#

That string ouputs the number that I want to add to

input_number.time_credits_personal_education
#

Oh. I need to google "how to set value of input_number from template

inner mesa
#

yes, you do πŸ™‚

sage stirrup
#

Before I dig into this .. can you tell me if it's possible to directly set the value of a input_number from template code? Or do I need to set it up in the automation or something?

#

I dont even know if that question makes sense. I just meant that I think it woudl be easy if I could write it all out in the template code but I dont know if thats possible.

#

My questions probably dont make sense I'm such a noob.

versed lava
#

What does the ``trigger.to_state.statedo in"{{ trigger.to_state.state if trigger.to_state.attributes.phone == number else this.state }}"`?

dusty grailBOT
inner mesa
#

all you have to do is call the input_number.set_value service, and there's even an example on that page of using a template

sage stirrup
#

@inner mesa Yes I ditched the script and did it in the automation. But I dont think this syntax is correct:

action:
  - service: input_number.set_value
    data:
      value: {{ (states('input_number.minutes_to_add') | float) + (states('input_number.hours_to_add') | float * 60) + (states('input_number.time_credits_personal_education') | float) }}
    target:
      entity_id: input_number.time_credits_personal_education
mode: single
#

I think I can't just put template code into the value spot right?

inner mesa
inner mesa
sage stirrup
#

AHHHH really!?

#

omgomgomgomg it worked! Thank you!

versed lava
#

sry btw for ping

inner mesa
#

it sounds like you're just asking what that template does

#

"{{ trigger.to_state.state if trigger.to_state.attributes.phone == number else this.state }}"

#

I misspoke earlier because I misread it. it's the new state

versed lava
#

oh, so it's the same as

{% if trigger.to_state.attributes.phone == number %}
  trigger.to_state.state
{% else %}
  this.state
{% endif %}

?

inner mesa
#

yes, if you added {{ }} to the values

versed lava
#

uh, yes of course

inner mesa
#

it's just a shorthand way of doing that

versed lava
#

I see

#

the order screwed with my brain tbh

inner mesa
#

it's just like reading a sentence

versed lava
#

yeah, it's so easy and was right in front of me the whole time...

sage stirrup
#

@inner mesa Is there a way to display a number on a dashboard instead of having it like an input field? I dont want to be able to change the value of the number unless it's the automation doing it.

#

I can display it like a gauge I guess. is that the only way?

inner mesa
#

Use a markdown card

sage stirrup
#

Ohhhhhhhhhhhh snap. Thank you

dusty grailBOT
versed lava
#

damn, that wasn't intentional

sage stirrup
#

@inner mesa Thank you for your help. I made a rewards system where I can earn time to do things I want to do, by completing time doing things I dont want to do. https://ibb.co/98cYnJY Thank you I really do appreciate it πŸ™

dull burrow
sage stirrup
#

hm. Well. Unfortunately theres a lot of automations. I should try to put it all in one file instead.

#

one sec lemme se if I can find it

#

I have the file editor I'm looking at the automations file.

dull burrow
#

Yea

sage stirrup
#

I wish I had one big awesome automation instead of all these seperate ones, but here's basically how it works.

  • Helper button for task I dont like doing (i.e. Cleaning/Laundry).

  • Helper button for the task associated to Cleaning Laundry that I get as a reward (i.e. Watching TV)

  • input_number entity that holds reward minutes earned (i.e. Watching TV)

  • input_number for minutes

  • input_number for hours

  • Automation that takes input for time logged doing work task saves it as time for watching TV (i put in math rules so it's not always 1:1 sometimes it takes say 4 minutes of work task to achieve 1 minute of fun task) https://www.codedump.xyz/yml/Yy0dBQfwtiwknb2Y

  • Automation that lets me claim earned time credits https://www.codedump.xyz/yml/Yy0dTQfwtiwknb2Z

  • Code for markdown card https://www.codedump.xyz/csharp/Yy0daQfwtiwknb2a

#

So basically if you add minutes or hours together it converts the hours to minutes and adds them together.. also.. if you add some time logged but after conversion it outputs a decimal like 1.666666666 minutes it rounds the minute so that you get whole numbers for minutes.. or... only one decimal place, so that it doesnt give grief when claiming credits..

#

all in all it took me about 4 hours to do. worth it though.

dull burrow
#

Thank you for the write up man

sage stirrup
#

No problem

dull burrow
#

I’m gonna copy it all to play with later πŸ™‚

sage stirrup
#

Yeah Maybe I should put it on github hey

#

and make a youtube video

#

I'm glad someone else finds it useful makes me feel like I'm not nuts haha

dull burrow
#

We are all nuts dude

sage stirrup
#

ha

#

The next thing I have to add is day rewards.. like.. Every 5 days of eating clean I earn one treat

#

But thanks to @inner mesa I didn't know how to code it at all I would have been stuck without his help.

inner mesa
#

I'm gonna watch some TV just for you

sage stirrup
#

Just so long as you're not taking my TV Watching credits I'm allllllll good with that

#

I could call this thing Virtual Parent 2022

#

"Do your homework and you can play call of duty"

#

except in my case it was "Do your homework and you can play Doom 2"

dull burrow
#

πŸ˜›

sage stirrup
#

Oh dang cool

dull burrow
#

gotta clean it up tomorrow i guess

sage stirrup
#

Very cool

#

well geez. thats great.

#

I guess it was useful enough hey. I'm flattered.

dull burrow
#

i might not even use it or use most of it.. but now i have it to share with others lol

sage stirrup
#

Thats very cool

dull burrow
#

i like knowing that i can point to something or look back on later

#

thx dude

sage stirrup
#

Well yeah its helpful I know I spent the time and I forsure wont be the first or last person that is trying to solve this problem

#

Soon elon will have all our brains connected like borg and we wont need github anymore haha

dull burrow
#

lol

#

i am now at 5 3d printers.. i think i fall into the crazy boat too

sage stirrup
#

Niiiiiiiice

#

I dont have one. But I would like one

#

I wish I had something that could print money, now that I'm thinking of 3d printers.

marble jackal
# versed lava damn, that wasn't intentional
    sensor:
      - name: gpdlatitude
        state: >-
          {% if trigger.to_state.attributes.phone == number_sprinter %}
            {% set value_json = trigger.to_state.state | from_json %}
            {{ value_json["latitude"] }}
          {% endif %}
#

BTW without the{% else %} {{ this.state }} the sensor will loose it's state on any new sms received in the sms sensor

neon laurel
#

what's the cleanest way to return true if an entity is part of a group?

#
    'light.ceiling_light')|list }}```
this returns the light if it's part of the group and an empty list if not
#

I could check if the list is empty I guess

#

but was wondering if I could pipe the command into something else to return true directly

marble jackal
#

or
{{ 'light.ceiling_light' in expand('group.bedroom_lights') | map(attribute='entity_id') | list }}

neon laurel
azure drum
#

Good morning. How can I store data to survive reboots. I want to store things like peak solar production and I want to store when that peak was reached. Something like "6594kW at 21.06.2022 14:23" How do I create, read and write a file in HA. I think that that file could be read and the entities restored at boot time. An update of the peak value could be done, whenever a peak is updated. I that a possible approach? Or are there other possibilities to do something like that?

marble jackal
#

trigger based template sensors will restore the state after reboot, or you can use an input_number to store the value

#

If I understand your question correctly, I would suggest a trigger based template sensor

azure drum
#

Thanks, then I will start experimenting with trigger based template sensors. The input_number I got working, but they create sliders or input fields. The secondary_info: last-updated shows time since last update, not an absolute time and date. I don't know how to get rid of the sliders and how to set absolute time and date there...

#

Maybe a new template class "entity_storage" is a new idea for the future to really store such max/min data like all time high or low values, with the time and date they occurred? Sinds such a thing is beyond my current capabilities, maybe somebody else finds that idea attractive as wall and adds it to HA???

marble jackal
#

you can always add a feature request on the forum

#

but this should probably work:

trigger:
  - platform: state
    entity_id: sensor.power_production
sensor:
  - unique_id: trigger_sensor_power_production_peak
    name: Power Production Peak
    state: >
      {% set n = trigger.to_state.state  %}
      {% if n | is_number and n | float > this.state | float(0) %}
        {{ n }}
      {% else %}
        {{ this.state }}
      {% endif %}
    unit_of_measurement: W
    attributes:
      datetime: >
        {% set n = trigger.to_state.state  %}
        {% if n | is_number and n > this.state | float(0) %}
          {{ trigger.to_state.last_changed }}
        {% else %}
          {{ this.attributes.get('datetime') }}
        {% endif %}
marble jackal
azure drum
#

Perfect! Erg bedankt!

marble jackal
#

and a correction in the state template πŸ˜…

versed lava
marble jackal
#

@versed lava sorry, you need to use from_json, not to_json

#
{% set test = '{"latitude":"1.000000","longitude":"1.000000"}' %}
{{ (test | from_json).latitude }}

returns: 1

mighty ledge
versed lava
tepid onyx
#

If I create a variable with a string that begins with an asterisks * the yaml parser blows chunks. e.g.:
dkim_line: "*@{{ dkim_domain }}"
This works:
dkim_line: " *@{{ dkim_domain }} " because of the space.
I've tried to escape with with both types of quotes and a backslash but no joy. Can this be done? It's like the parser is still seeing it as an anchor reference even when it's escaped..

azure drum
marble jackal
#

Yes, you should indent it two spaces and add a dash (-) before trigger:

vocal agate
jagged obsidian
#

indentation is a bit too deep on that config

vocal agate
#

How to get it more shallow?

#

the other sensors working fine but they do not start with an integer

jagged obsidian
#
tempkiz1:
  friendly_name: "Temperatur Kiz1"
  unit_of_measurement: "Β°C"
  value_template: '{{ states.climate.00201d89bc94c7.attributes.current_temperature }}'  
#

what does that value_template show in developer tab?

vocal agate
#

the sensors.yaml is not valid like this

vocal agate
jagged obsidian
vocal agate
#

I think the code does not like the integer behind the climate "."

jagged obsidian
#

numbers in entities should be enclosed in []

silent cedar
#

Hello respected members. I have created an automation with to get an alert through telegram bot whenever my camera stream is down. The issue is I have six cameras and I also want to get which camera is down. Is it possible? Plus I want the automation to stop once I have recieved an alert and again alert me when the stream is back online. Please help.

mighty ledge
mighty ledge
vocal agate
#

got it

#

value_template: {{ state_attr('climate.00201d89bc94c7', 'current_temperature')}}

mighty ledge
#

whenever you have numbers as the object_id starting character, it's suggested that you change the entity_id if you plan on using states.xxx.yyy.attributes.zzz

#

(and remove the numbers)

vocal agate
#

The entity_id comes from a integration

mighty ledge
#

and you can change that

#

just like you can on any entity

vocal agate
#

in the developer tools state?

mighty ledge
#

anywhere you can access the entity

#

then click update

vocal agate
#

Thanks Petro and blackadder

mighty ledge
#

you have

#
template:
  sensor:
  ... your other items ...
  - trigger:
    ...
    sensor:
    ...
#

it needs to be

#
template:
- sensor:
  .... your other items ...
- trigger:
  ....
  sensor:
  ....
#

you have to add a dash in front of your first sensor:, then indent all sensors under that (by 2). Then your second - will be the trigger.

azure drum
mighty ledge
#

be prepared to share your current automation as well. People won't write these things from scratch for you.

fossil venture
silent cedar
#

Please atleast give me a direction so that I can figure it out

azure drum
silent cedar
#
entity_id:
  - camera.192_168_29_100
  - camera.192_168_29_101
  - camera.192_168_29_102
  - camera.192_168_29_103
  - camera.192_168_29_104
  - camera.192_168_29_105
  - camera.192_168_29_106

from: idle
to: unavailable
for:
  hours: 0
  minutes: 0
  seconds: 10```
azure drum
silent cedar
#

This is my trigger code

fossil venture
silent cedar
#

This is my action code to send telegram message

#
data:
  message: Camera stream is down
  title: Alert```
mighty ledge
#

replace your message with what tom posted

marble jackal
#
    attributes:
      datetime: >
        {% set n = trigger.to_state.state  %}
        {% if n | is_number and n | float > this.state | float(0) %}
          {{ trigger.to_state.last_changed }}
        {% else %}
          {{ this.attributes.get('datetime') }}
        {% endif %}
#

btw, if it's kWh you are interested in, the peak will always be at the end of the day, so it makes no sense to save the entire datetime

#
    attributes:
      date: >
        {% set n = trigger.to_state.state  %}
        {% if n | is_number and n | float > this.state | float(0) %}
          {{ now().date() }}
        {% else %}
          {{ this.attributes.get('date') }}
        {% endif %}

So this will do fine as well

azure drum
#

Oh, haven't thought about that, but you are right!

silent cedar
marble jackal
#

You can not use the RUN ACTIONS button to test it, it relies on a trigger, so it needs a trigger

silent cedar
#

I then changed trigger to state and recieved the telegram message which says "none is unavailable" but the stream is down

marble jackal
#

The template is correct, but you can't test this using the RUN ACTIONS button

#

you can try to set the state in devtools >States for one of the cameras

silent cedar
marble jackal
#

was the state already unavailable? It needs to change from idle to unavailable as per the settings in your trigger

silent cedar
#

No it was first idle and then changes to unavailable

mighty ledge
#
  1. remove the from, it's not needed. 2. If you reload the automation, it needs to change state for it to fire. It will not fire on it's own if it's already been unavailable after a reload.
silent cedar
#

Removed 'from'

#

Only kept to unavailable

silent cedar
#

So changes trigger with state but then getting the same message none is unavailable

mighty ledge
#

how are you running it? It's been stated many times that this can only be executed a specific way.

silent cedar
#

I saved the code

mighty ledge
#

you can't use 'test actions'

#

you actually have to have a camera go from a different state to unavailable

silent cedar
#

I unplugged the cat 6 cable of one of the camera

mighty ledge
#

how did you do that exactly?

silent cedar
#

I unplugged the cat 6 cable of the camera

mighty ledge
#

and then you waited 10 seconds?

silent cedar
#

Yes

mighty ledge
#

and what does the automation trace say?

#

and what's the state of the camera?

silent cedar
#

Shall I keep states instead of trigger in command?

mighty ledge
#

no, you keep exactly what tom wrote

silent cedar
#

{{trigger.tostate.name}}

#

Alright

mighty ledge
#

that's not what tom wrote

#
{{ trigger.to_state.name }}
#

he also has his whole message in quotes

#

which you have to do as well.

silent cedar
#

I said in short to highlight the trigger or state before to_state

mighty ledge
#

so back to my other questions...

#

and what does the automation trace say?
and what's the state of the camera?

silent cedar
#
Result:
params:
  domain: telegram_bot
  service: send_message
  service_data:
    message: 192_168_29_104 is unavailable
    title: Alert
  target: {}
running_script: false
limit: 10```
#

This is automation trace

#

I didn't recieve any alert this time

#

In trace it is showing the camera entity id but I didn't get alert on telegram

#

Feels weird

mighty ledge
#

nothing wierd about it. It fired the message, however telegram didn't do what it should have. Look into why telegram failed.

silent cedar
#

I don't know what's happening

#

I restarted my system

#

But I'm not getting the telegram alert

#

From services under developer tools I'm able send a message service to send 'hii' message

mighty ledge
#

post the yaml that you're using in the developer tools, there's a button to switch to yaml mode

silent cedar
#

I'm getting the following error "Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'" When click run actions for my automation under automation tab

silent cedar
#

configuration.yaml of home-assistant?

marble jackal
marble jackal
silent cedar
#

Just a minute

dusty grailBOT
#

Please use a code share site to share code or logs, for example:

Please don't use Pastebin, since it can randomly add spaces to the main view. Please also don't share text as images since it makes it harder for people to help you. Remember that others may have colour blindness, impaired vision, etc.

mighty ledge
silent cedar
#

My home-assistant configuration

silent cedar
#

I'm using this to check whether the telegram service is fine

marble jackal
#

can you share the code of this specific automation? you can switch to yaml in the 3dot menu at the top

dusty grailBOT
marble jackal
#

that looks fine. Are your cameras plugged in again?

silent cedar
#

Yes

mighty ledge
silent cedar
#

Because I can call basic send message service from services

#

And when hi I get the message I send using the service

#

Oh my god

#

Got it

#

I think the telegram is blocking ip address in messages

#

Shit

silent cedar
#

But when I send a meesage 192.168.29.104 I'm able to receive it

mighty ledge
#

Why don't you just name your cameras something other than the IP address

silent cedar
#

To confirm please can anyone of you check

#

?

mighty ledge
#

I don't have telegram

marble jackal
#

"{{ trigger.to_state.name | replace('_', '.') }} is unavailable"

#

me neither

mighty ledge
#

I use the mobile app to send myself notifications

silent cedar
#

I'm using this code to send message

#
data:
  message: 192_168_29_104 is unavailable"
  title: Alert```
silent cedar
silent cedar
fossil venture
#

Works fine here.

silent cedar
fossil venture
#

No

marble jackal
#

no, that won't work

silent cedar
#

Can to change friendly_name to something to understand instead of xx_xx_xx_xx format?

azure drum
marble jackal
#

@candid nacelle I kinda hoped I mentioned #templates-archived enough

service: select.select_option
data:
  entity_id: select.thing
  option: >
    {% set options = state_attr('select.thing','options') %}
    {% set current = states('select.thing') %}
    {% set i = options.index(current) + 1 %}
    {{ options[i % options | count] }}
mighty ledge
mighty ledge
silent cedar
silent cedar
silent cedar
#

One query

#

I want to implement scripts to make the automation smarter

#

The code you guys helped me with keeps sending the unavailable message

#

I want it to send me the message once it's down and once it's restored

#

What condition shall I use

#

Point me in the correct direction

mighty ledge
mighty ledge
dusty grailBOT
#

@sage stirrup Please use a code share site to share code or logs, for example:

Please don't use Pastebin, since it can randomly add spaces to the main view. Please also don't share text as images since it makes it harder for people to help you. Remember that others may have colour blindness, impaired vision, etc.

sage stirrup
#

Here are four automations, two of each type.

mighty ledge
silent cedar
gray holly
#

Hey guys in a script ive defined a variable UUID is it possible to change it from a template in sequence? I tried using set uuid = <value> but doesnt seem to work

silent cedar
#

I'm sorry

#

I created a new automation changed 'to' to 'from'

mighty ledge
silent cedar
#

Is there a order in which these automation execute?

mighty ledge
#

are you using the UI?

gray holly
#

they run from top to bottom

silent cedar
#

Yes I used ui and copied the yaml code

mighty ledge
#

no order, they execute when they trigger

#

if you use yaml, there's no order, they execute when they trigger, however when they are loaded into the system, they are loaded top of the file down.

gray holly
mighty ledge
gray holly
#

is there anyway i can define script variables from inside a wait template?

mighty ledge
#

you can overwrite things you set, i.e. {% set xyz = 1 %} followed by a {% set xyz = 2 %}. However, if the variable already exists in your namespace, you cannot overwrite it. I.e. if it comes from another variable in the sequence

gray holly
#

hmmm ok

mighty ledge
#

just make it a different name

#

you don't need to reuse what was previously declared

gray holly
#

My logic is I have a template to run some complex python code and then output somthing that a following if statement in the sequence will check if exists

#

{% set uuid = d_beacons.detected[d_beacons.distance.index(min(d_beacons.distance))] %} so this is the line that sets the variable uuid to something and then i have an if condition next is sequence checking if it was defined
- if: - condition: template value_template: "{{ uuid is defined }}" alias: Check if UUID was set

#

hope this makes sense

mighty ledge
#

I'm not sure how you can run python code from a template

gray holly
#

jinja2 i mean

#

which is python for templating

mighty ledge
#

yeah, that's not correct

#

it's jinja, that's it

#

it has python objects

#

but the code is 100% jinja

#

anyways, make a variable and just call the uuid

#
- variables:
    uuid: .... your complex code ...
... later on ...
- if:
  - condition: template
    value_template: "{{ uuid is defined }}"
    alias: Check if UUID was set
gray holly
mighty ledge
#

yeah, it's written in python

#

it's not using python code to template

gray holly
#

and the syntax is python. Or inspired in python anyway thats besides the point

mighty ledge
#

you're using jinja syntax

#

no

#

jinja syntax

#

it's similar to python, but it's not python

#

if you try pythonic expresssions, many of them do not work.

gray holly
#

Thats true

inner mesa
#

Like many languages are similar to other languages

gray holly
#

Ok ill call it by its name then jinja2

mighty ledge
#

sure whatever

silent cedar
#

I'm reciveing camera restored alert even I haven't restored the camera.

mighty ledge
#

just don't call it python because that confuses the experts πŸ˜‰

gray holly
#

dude what. Are we really getting mad cuz of this?

silent cedar
#

I'm getting unavailable and restored message alternatively

mighty ledge
#

I'm not mad at all

gray holly
silent cedar
#

And each message I receive is after 10 sec not stopping

mighty ledge
#

i'm saying 'sure whatever' as in call it whatever you want

#

just don't call it python, cause it's not python

gray holly
#

ok

mighty ledge
#

jinja, jinja2, templates, etc

#

but anyways, jinja is limited to scope, and to top it off, there's a restriction set in place on automations and scripts

#

anything output to a variable... i.e...

variables:
  xyz: "{{ ... }}"

will be static from that point forward. You won't be able to call another...

variables:
  xyz: "{{ ... }}"

to overwrite it

gray holly
#

that worked @mighty ledge thanks for the help

mighty ledge
#

np

gray holly
#

And I wont call it python anymore πŸ˜‚

mighty ledge
#

lol, it was just confusing because we haven't added any way to execute python in jinja

#

so I was curious what you were doing to get that to happen

gray holly
#

I know I recognize my mistake just messing with ya

mighty ledge
#

I want to add a method to do that, but it's alot of work and we'd want to add macro support too

gray holly
#

there is a js library that does that

#

i saw it in a youtube video onde

#

once*

mighty ledge
#

yeah, I'm sure there is, but we have to add it in a way that works with HA, so it's a whole 'situation'

gray holly
#

its called pyscript

mighty ledge
#

well yeah, there's pyscript, but I'm specifically refering to adding a function into templates that are usable in all templates

gray holly
#

are you a developer for HA?

mighty ledge
#

I add stuff here and there, but not on the dev team

gray holly
#

something like that

#

I wanted to get more envolved cuz i use HA a lot but im really busy with work, and my projects

mighty ledge
#

yeah then just volunteer once and a while

#

that's all I do

#

I'm in the same boat as you

#

I dev fulltime and when I get home, I usually don't want to dev

#

unless I really want a feature

#

then I add it

gray holly
#

the open source project i currently support is alexa-actions

#

which allows for actinable notifications with alex

mighty ledge
#

if you know python, adding or updating integrations is super easy

gray holly
#

how do you test stuff?

mighty ledge
#

there's a developers document section, it shows you how to create a dev environment

#

using vscode

gray holly
#

makes sense

mighty ledge
#

it's easy, although some people screw it up. If you've used vscode, you'll have no troubles. Also, if you understand the python build process, you'll have no troubles.

gray holly
#

not a fan of vs but ill give it a try one day

#

im a jetbrains kinda guy

#

@mighty ledge mind sharing you github?

mighty ledge
#

It’s on my avatar

#

Or not, I thought it was

silent cedar
#

I have tried playing with to and from but still getting unavailable and restored alerts alternatively

#

Please help

gray holly
#

what are you trying to do @silent cedar ?

mighty ledge
silent cedar
#

And to receive an alert when camera is restored

#

But when I remove the cat 6 cable of my camera I also recive the alert that camera is restored even if it is unavailable

gray holly
#

youre using home assistant i suppose? Why not use phone notifications?

silent cedar
#

I only want to receive msg once

gray holly
#

directly from the app?

#

anyway can you share the yaml file of the automation?

silent cedar
#

But im getting msg continously until the camera is restored

silent cedar
silent cedar
gray holly
#

you have the companion app for home assistant

#

and you can use the notify service to send push notifications to phones

silent cedar
#

I'm using telegram because it's linked to a tool Im currently using

silent cedar
dusty grailBOT
silent cedar
#

This is yaml for alert when camera is restored

gray holly
#

and when the camera goes offline?

#

do you have that yaml too?

silent cedar
#

Yes

dusty grailBOT
gray holly
#

have you tried settings from: idle to: unavailable

#

instead of just using to?

silent cedar
#

Yes did that

#

But results are same

gray holly
#

can you check device change log or history and send a print?

#

I want to check if any of the devices are jumping from states

#

which could be the cause of the issue

#

which to fix this would be to increate the for time

silent cedar
#

Yes I checked in nvr and overview tab of home-assistant

#

Device is indeed changing states

gray holly
#

do the devices like power down to save energy?

silent cedar
#

No

gray holly
#

or disable wifi when there is no movement?

silent cedar
#

No

gray holly
#

does the state jumping only occur during the beggining of removing the cat6 cable

#

or is it something that happens on a regular basis?

silent cedar
#

As of now on removing of cable

gray holly
#

then the thing i can recomend is increasing the time to like 30 seconds see if its enough

silent cedar
#

Plus I want to fix a bigger issue first

#

How to avoid the automation to stop after sending one message

#

I want only one message you once the camera is unavailable

gray holly
#

you can create an auxiliar entity an then in the conditions say only if 5 minutes passed since the last trigger

dull burrow
sage stirrup
#

@dull burrow much improved yea!

#

I can't wait to get this all into a single automation. that'll be nice!

sage stirrup
jolly swallow
#

I clearly do not know what I am doing, but I do know what I'm trying to do.

I'm trying to create a simple graph that will show when my HVAC system is either, heating, cooling, or idle. I was able to locate the proper values but I don't know how to make it an actual sensor.

Invalid config for [sensor.template]: expected dictionary for dictionary value @ data['sensors']['friendly_name']. Got 'HVAC Status'
expected dictionary for dictionary value @ data['sensors']['value_template']. Got '{% if is_state_attr (\'climate.hallway\', \'hvac_action\', \'cooling\') %}\n  "Cooling"\n{% elif is_state_attr (\'climate.hallway\', \'hvac_action\', \'heating\') %}\n  "Heating"\n{% else %}\n  "Idle"\n{% endif %}'. (See ?, line ?). 
- platform: template
  sensors:
    friendly_name: "HVAC Status"
    value_template: >-
      {% if is_state_attr ('climate.hallway', 'hvac_action', 'cooling') %}
        "Cooling"
      {% elif is_state_attr ('climate.hallway', 'hvac_action', 'heating') %}
        "Heating"
      {% else %}
        "Idle"
      {% endif %}
inner mesa
#

You didn't follow the format from the docs

#

You didn't provide a sensor name

jolly swallow
#

Can I name it w/e I want?

#

For example

- platform: template
  sensors:
    hvac_status:
      friendly_name: HVAC Status
      value_template: >-
#

Ah I see now, god yaml is so bad.

#

Thank you for your help!

sage stirrup
#

hi @mighty ledge not sure if you're there, but I tried to save the one script to rule them all and got this message

Message malformed: required key not provided @ data['trigger'][0]['platform']
sage stirrup
# dull burrow ooh you guys improved it

I tried saving the code but it didn't work. I can't stay online much longer tonight I have a bad injury and it's acting up. Hopefully Petro will be around to lend a hand sometime. Looks much simpler than what I was doing I spent a lot of time duplicating and copying automations.

dull burrow
#

hope you feel better

#

i havent played with it yet either i just saved it for later

slim elk
sage stirrup
#

oh!

#

Thank you @slim elk I'll check it out now

#

Saved! Thanks again @slim elk !

slim elk
#

np

cerulean blaze
#

Hey guys im looking for some help and I think you guys might know a little more about it

#

I have MQTT setup to where it can push a message to each of my devices and open apps / run programs / etc. But I can't figure out how to configure a front end card to where I can make the payload variable.

Like a textbox for payload "Text Goes Here" that uses a template to send the string to my service

Anyone know what I'm missing?

slim elk
cerulean blaze
#

Im using that im just having an issue sending that to a script and to mqtt

slim elk
#

share what you have so far?

cerulean blaze
#

Ok I got it partially working in parts lol

#

So here is what is working and will open discord on the desired pc:

type: button tap_action: action: call-service service: script.mqttalexis service_data: whatever: open discord

#

This has a text box that I can use AND DOES SET THE INPUT_TEXT CORRECTLY but it still will send "input_text.mqttpayload" as the payload...

- type: entities entities: - entity: input_text.mqtt_payload type: custom:text-input-row - type: call-service name: ' ' icon: mdi:voice action_name: Send service: script.mqttalexis service_data: whatever: input_text.mqtt_payload

#

Thanks @slim elk

slim elk
#

whatever: "{{ states('input_text.mqtt_payload') }}"

cerulean blaze
#

Executed: September 23, 2022 at 8:54:07 PM Result: params: domain: mqtt service: publish service_data: topic: alexispc payload: '{{ states(''input_text.mqtt_payload'') }}' target: {} running_script: false limit: 10

#

@slim elk did I do something wrong?

#

should I just do "{ {{ states('input_text.mqtt_payload') }} }" instead of whatever ion the script and not even pass the data directly?

slim elk
#

payload: '{{ states("input_text.mqtt_payload") }}' or payload: "{{ states('input_text.mqtt_payload') }}"

cerulean blaze
#

@slim elk I just changed the script to payload: '{ {{ states(''input_text.mqtt_payload'') }} }' and that worked

#

thank you so much!

slim elk
#

np glad I could help

cerulean blaze
#

@slim elk I sent a pm of nitro gift lol I really do appreciate the help

slim elk
#

wow, thank you. Much appreciated πŸ™‚

abstract sapphire
#

What am I missing here? color_temp is an attribute of the light.workshop entity.

{% if state_attr('light.workshop', 'color_temp') = 365 %}
scene.scene_workshop_white
{% elif state_attr('light.workshop', 'color_temp') = 153 %}
scene.scene_workshop_yellow
{% endif %}
#

Or because it's a numeric value do I need to use this instead?

{% if numeric_state('light.workshop', 'color_temp') = 365 %}
scene.scene_workshop_white
{% elif numeric_state('light.workshop', 'color_temp') = 153 %}
scene.scene_workshop_yellow
{% endif %}
marble jackal
#

No, that last one is not correct

#

That first one could work, but you only take into account 2 of many possible color temperatures

#

@abstract sapphire How are you using this template?

#

Also take into account that that current color_temp is not known if the light is turned off

abstract sapphire
#

Yeah it's only for light when on

#

Using it in an automation, when a zha_event is triggered

#
service: scene.turn_on
target:
  entity_id: >-
    {% if state_attr('light.workshop', 'color_temp') = 365 %}
    scene.scene_workshop_white
    {% elif state_attr('light.workshop', 'color_temp') = 153 %}
    scene.scene_workshop_yellow
    {% endif %}
metadata: {}
marble jackal
#

Well, like I said, there are many color temperatures possible, and you only take two into account

#

So this will fail when it's any of the other possibilities

#

Oh, and you need to use == instead of =

marble jackal
abstract sapphire
tepid oak
#

Hi all. I've been searching this for a week or so and I just can't come up with a solution. I have an apex chart that shows my daily energy usage for the last 7 days. I would like to overlay this with a running average of the max consumption for the time period. (TotalDay1+TotalDay2+TotalDay3)/3 (for three days). I know there is a weekly power meter but that always restarts on Monday not constantly rotating for the previous 7 days. Can anyone point me to and example template of summing the last x days total consumption? I feel I just need to rotate through the max of daily bins but for the life of me I can't wrap my head around how to do it.

mighty ledge
marble jackal
#

Maybe with a trigger based template sensor, which stores the pevious_period attribute of a daily utility meter sensor in the attributes, and had the average of the last 3 values in the state

marble jackal
#

@mighty ledge is there any advantage of using is sameas instead of == besides maybe this particular case

{{ 1 == true }} # True
{{ 1 is sameas true }} # False
mighty ledge
#

never seen sameas

#

odd, i would assume it would be the same as {{ 1 is True }}

#

it's about the memory address, so it's like is. I don't see a reason to use it

#

You'll rarely want the same memory address

#

It could be useful for checking state objects only

#

like, the entire object

#

other than that, there's better checks for simple objects

willow rapids
#

if I wanted to have this: https://pastebin.com/CpywY45N result in a No items being delivered, if all sensors answer No... is that possible? Currently that looks like No pieces of mail will be delivered. No USPS packages are in transit. No Fedex packages are in transit. No UPS packages are in transit. No Amazon packages are in transit.

#

and I was hoping to get 'No mail, and No Packages will be delivered'...

tepid oak
# mighty ledge you can't do that in a template.

Thanks. Any thoughts on how I could go about this outside of templates? I thought about getting "yesterdays value", which is an attribute of the utility meter, just after midnight and storing it each day but even then I don't know how to sum up the last 7 values that I stored. How are all the chart packages doing the binning? Is it all javascript in the background?

mighty ledge
#

whatever you can dream up using the statistics sensor in combinations with other sensors

#

templates don't look at history so templates aren't an option

silent cedar
#

I have created an automation where I get an alert when the camera is down and an alert once again once the stream is restored but my automation keeps continuously sending me alert "Alert
The camera stream for camera Shed2MainGate is None." once the camera is down. The camera name received in the alert is correct. Why is it sending me none instead on "unavailable" (state)? Plus why not it is sending me "idle" (state) once the camera is restored.

#

My yaml

dusty grailBOT
silent cedar
#

I made a change in the yaml file. Now i'm the getting state names (resolved the issue where I recieved "none" instead of current state). The only issue now is that still the camera is down but I'm getting "idle" Alert.

#

Alternate idle and unavailable alerts

#

Updated yaml code

dusty grailBOT
silent cedar
#

When the second iteration of automation starts will the to_state become from_state?

marble jackal
#

There is no attribute state

#

So state_attr(entity_id, 'state') isn't going to work

#

Use states(entity_id) or trigger.to_state.state like you do in the condition

#

Btw, the condition is not needed when you add to: ~ to your trigger

silent cedar
silent cedar
marble jackal
slate crater
#

hi guys. i'm trying to do something i didn't know if it's possible. I want to have a boolean switch in my sister's dashboard that enables or disables a "Maintenance" user. I already have a dashboard button that navigates to /config/users but she will have to click the "Maintenance" user, enable it and update, with a few more clicks... i was trying to automate that process so she could easily enable or disable that specific user with a single click at the boolean switch. Can that be done?

silent cedar
marble jackal
silent cedar
#

By that I mean the second time the automation executes

marble jackal
#

And could you stop posting text-walls and use a code website yourself instead of letting the bot do it for you

dusty grailBOT
#

[Rule #6](#rules message): 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.

For sharing code or logs use a code share site such as https://dpaste.org/ (pick YAML for the language) or http://pastie.org/ (pick YAML for the language).

silent cedar
marble jackal
silent cedar
marble jackal
#

If it changes from unavailable to something else it will have unavailable as trigger.from_state.state

silent cedar
#

What change shall I make in my yaml?

silent cedar
#

I'm unable to think of any possible solution

#

Ohh. I got it. The from_state is alternating in each iteration

#

First idle then unavailable then again idle and so on

#

Thats why I'm getting alternating state alerts

#

What condition, script or any other property can I use to stop this alternating of states

#

?

marble jackal
#

Your cameras shouldn't alternate between idle and unavailable that much

#

I would start there

#

Why is that happening?

silent cedar
#

No they are not alternating

#

I have removed the cat 6 cable of one of my camera to test automation.

marble jackal
#

Okay, then I don't understand what the issue is now

#

You made an automation to inform you on every state change

#

It is doing that

silent cedar
#

The camera is still down but I'm getting idle alert

#

I will share the screenshot of the alert

#

Just a minute

marble jackal
#

Well, apparently it became idle, otherwise the trigger object will not have that to_state

silent cedar
marble jackal
#

No

silent cedar
silent cedar
marble jackal
#

Yes, which shows that Home Assistant received an event that the camera changed state to idle

#

If it did not do that, because it has unplugged, and had not been plugged in, the problem is in the integration, and not in the automation

silent cedar
marble jackal
#

I don't know what you are using

silent cedar
#

This is 5th day of me playing with home-assitant. I'm new to programming and automation stuff.

#

I don't know what I'm that failing to explain

silent cedar
#

I feel the issue is with my yaml

#

Because when I plug the cat 6 cable I stop getting the alerts

marble jackal
marble jackal
#

Alternating between unavailable and idle

silent cedar
#

Correct

marble jackal
#

This means the integration is reporting the camera as such

#

You will also see that if to look at the history of the camera

#

This is for example the history of the motion sensor in my toilet

#

How does that look for your camera?

silent cedar
#

Just a minute

#

I'm sending the logbook image

#

This is it

#

Please check

marble jackal
#

Okay, so that confirms what I was saying, the camera is reported as idle and unavailable by the integration

silent cedar
#

How can I solve this Integration issue?

marble jackal
#

As a work around you could use a ping sensor

cyan raven
#

I want to control a dimmer via a motion sensor. Move hand close for bright, away to dim. I'm no programmer, but this sounds cool...in theory. Any thoughts on how to do this in Home Assistant?

celest brook
#

Is this the right syntax?
{% set heat1 = states('binary_sensor.call_heat_woonkamer_0_3') %} {% set heat2 = states('binary_sensor.call_heat_keuken_0_3') %} {{ heat1 or heat2 }}
Right now it seems to respond to the first sensor, but not to the second one.

inner mesa
#

no, because states are strings

#
        {% set heat1 = is_state('binary_sensor.call_heat_woonkamer_0_3', 'on') %}
        {% set heat2 = is_state('binary_sensor.call_heat_keuken_0_3', 'on') %}
        {{ heat1 or heat2 }}
celest brook
#

That makes no sense to me whatsoever, which is presumably why google didn't tell me about it. But okay, it's a design choice I can handle. Thank you!

#

Yup, that indeed does what I was expecting, not that I had any doubts it would.

hallow pebble
#

Any reason why this template is working:

  • service: notify.mobile_app_{{'galaxy_a32' if trigger.event.data.device_id == markus_nfc_reader else 'pixel_3a'}}
    But this one is not?
  • service: input_boolean.turn_on
    entity_id: input_boolean.{{'markus' if trigger.event.data.device_id == markus_nfc_reader else 'jessica'}}_asleep
inner mesa
#

hard to say without knowing what "markus_nfc_reader" is

#

it looks like an undefined variable

#

you haven't said how it isn't working, either

hallow pebble
#

Sorry, the markus_nfc reader is defined as a variable.
If I have the lower part in the automation I get the following log:
Invalid config for [automation]: not a valid value for dictionary value @ data['action'][1]['entity_id']. Got None. (See /config/configuration.yaml, line 165).

marble jackal
hallow pebble
#

but a very similar template is working i.e. the one in the first line

celest brook
# marble jackal You could have used the `bool` filter on your version ```jinja {% set he...

I think I see what you’re saying, but if binary_sensor states are strings (of all different kinds depending on the type of binary sensor it happens to be) that seems like you’d be relying on the bool filter to know which of those strings corresponds to true for all of those pairs of values. I don’t think I’m ready to trust to that in the general case, and I think I’d be flummoxed if I ever accidentally ran into a counterexample, so I’m going to stick RobC’s version into my mental toolkit.

inner mesa
marble jackal
celest brook
#

I learn with every message! It’s just… wow, the learning curve is steep for this stuff. I feel like I’m getting there, but I don’t yet fully grok the system.

marble jackal
vivid jay
#

I have some plugs that only have current/power/voltage. I've started to look into getting consumption from that but would appreciate any pointers

celest brook
celest brook
vivid jay
celest brook
#

On ^ that url turning power into energy is a literal example, btw.

rustic raft
#

Using a template to set the for: seconds amount, but it's erroring out and thinking I'm not setting the seconds amount. I tested the template and it works fine. How do I apply the template to the blueprint seconds attribute correctly? (seconds_delay is a valid variable)

          for:
      hours: 0
      minutes: 0
      seconds: >
        {% if is_state('binary_sensor.night_mode', 'on') %}
          180
        {% else %}
          {{ seconds_delay }}
        {% endif %}```
marble jackal
#

What is the error you get?

rustic raft
#

assuming that means the template isn't evaluating to anything consumable by the seconds field

marble jackal
#

Yes, and that would mean the variable is not valid

#

.share the entire code

dusty grailBOT
#

Please use a code share site to share code or logs, for example:

Please don't use Pastebin, since it can randomly add spaces to the main view. Please also don't share text as images since it makes it harder for people to help you. Remember that others may have colour blindness, impaired vision, etc.

rustic raft
marble jackal
#

And the automation created using this blueprint?

rustic raft
marble jackal
proud plume
#

Anyone have any thoughts why something as simple as {{ state_attr('weather.vancouver', 'forecast')[0] }} will sometimes return None? Is there a way to work around this other than adding default()? I have a bunch of automations that rely on weather attributes and at least a couple times a month this call returns None. I don't know if it's transient or how long it lasts.

marble jackal
#

state_attr() will return none when the attribute doesn't exist (or when it is none of course)

proud plume
#

yes for sure

marble jackal
#

Adding [0] to it will result in an error then

proud plume
#

so I guess the question I'm really asking is: How do people deal with the Weather integration not returning data reliably?

marble jackal
#

I combined 8 different weather integrations into one using a template weather

proud plume
#

lol. the belt and suspenders and an extra 6 sets approach? πŸ˜„

marble jackal
#

Maybe, but I always have a forecast available

proud plume
#

wanna share your template? πŸ™‚

marble jackal
#

It uses a template sensor to determine which integrations to use

#

You might want to change the units

celest brook
#

What happens when one says rain and the other says sun? That's more of a philosophical question than a practical I suppose since I can read the source.

marble jackal
#

And mentions the others (in the forecast)

#

Example:

- datetime: '2022-09-28T00:00:00+02:00'
  condition: rainy
  condition_all:
    - partlycloudy
    - pouring
    - rainy
  precipitation_probability: 89
  wind_bearing: 252.1
  temperature: 14.2
  templow: 6.3
  wind_speed: 12.4
  precipitation: 6.4
  entities:
    - list of entities used for this forecast```
neon laurel
#

- {{trigger.to_state.state.attributes.rgb_color[0]}}
is this the correct way to extract the value for red on the trigger light?

marble jackal
#

Looks fine

neon laurel
#

getting an error

#

'str object' has no attribute 'attributes'

#

got it

#

no need for '.state'

tame gust
#

Hello, how to create an template for the download speed, upload speed en ping for speedtest integration please. Want to add it in the mushroom template card. Thx

inner mesa
#

Depends on how you get that data, but the answer is there

ivory lily
#

This template is giving me the time in HH:mm:ss: {{ timedelta(hours=(states('sensor.dishwasher_runtime_today')|float)) }}. Is it possible to convert it to HH:mm?

tardy sphinx
#

Is there a "best" way to get multiple values from an entity's attributes, or do I just have to template up a bunch of new sensors?

inner mesa
#

Depends on what you want to do with them. You can often use attributes directly in cards

tardy sphinx
inner mesa
#

Do what exactly?

tardy sphinx
#

Test out cards that fetch attributes as opposed to main data

inner mesa
#

Review the docs for the card you want to use

#

The entities card supports attributes

#

Lots of custom cards do. The markdown card does

tardy sphinx
inner mesa
#

Only if you're using YAML mode for your dashboard

tardy sphinx
inner mesa
#

The directory? No

rose scroll
queen viper
#

I am trying to figure out the "best" way to create a history stats sensor for "Last week". (As in Mon -> Sun). But, i just end up with ridiculously complex expressions. So, what shortcut am I missing here?

slender whale
#

Quick one, i am trying to send an MQTT template topic {"warning": {"duration": 2, "mode": "emergency", "strobe": false}} this is fully copied from the zigbee2mqtt example. When it try to run this in Home Assistant call service MQTT i get the following error. failed to call service mqtt.publish value should be a string for dictionary value @daring linden[payload_template]. Got none.. any pointers?

queen viper
#

Not loading, and looks like a video site? Why not just post the code?

slender whale
azure drum
#

Any idea?

marble jackal
#

Is the source sensor a template sensor as well?

dusty grailBOT
#

@slender whale Your message has been deleted as it contains a link or a domain name 'pasteboard_dot_co' that is on the blocked list because of: 'Virus detected!'.
Please re-post by removing/changing the domain name/link. Your original message has been DM'ed to you.

azure drum
marble jackal
#

It looks like the sensor is triggered by the new state of the source template sensor when it didn't recover it's state yet. That trigger writes unknown or unavailable to the state, and then won't recovery the old state anymore

#

The above is just my assumption by the way

azure drum
sacred sparrow
#

how can I make this work```
if:

  • condition: numeric_state
    entity_id: media_player.nest_mini
    attribute: volume_level
    above: "{{ input_number.nest_default_volume_level - 0.01 }}"
    below: "{{ input_number.nest_default_volume_level + 0.01 }}"
    then:
  • service: media_player.volume_set
    target:
    entity_id: media_player.nest_mini
    data:
    volume_level: "{{ input_number.nest_default_volume_level }}"
marble jackal
#

You can not use templates voor above and below in a numeric state condition

#

Use a template condition instead

marble jackal
azure drum
marble jackal
#

Use the input_number as value for a template sensor

#

And put the template sensor on your dashboard

#

There is a feature request for conditions in the trigger based template sensor which would help in this case

azure drum
#

Okay, that is worth a try. But maybe I need some links to examples to handle it in a python script. I have no idea yet how to interface with ha's entities. So I am open to learn that as well. Maybe a little piece of demo code that you could send me a link of?

#

OR, maybe others are interested in an feature addition to HA, to keep max/min values on a permanent basis. I don't think that I am the only one with that need. The usage of input_number for that, seems to be a currently widely just tweak to do exactly that. I think that should be added to ha. My knowledge is not yet enough to generate a feature request that really to the point of it. How can we generate attention to such an addition?

#

These min/max templates could have an attribute min/max that makes them "immune" of becoming overwritten with a lower or higher value, depending on min or max...

#

In addition to that we would need a function to reset these specificaly..

azure drum
#

If not, what is the key the recovery file is sorted by. Entity-ID or any other data that I could influence to reorder the recovery file?

marble jackal
#

That I don't know

sacred sparrow
#

how come I can get this to work in an automation service: media_player.volume_set target: entity_id: media_player.nest_mini data: volume_level: "{{ states('input_number.nest_default_volume_level')|float / 100 - 0.01 }}"

#

but it works in the Template editor

marble jackal
#

@sacred sparrow what is the error you see in the logs?

icy ravine
#

Hi all - looking for some assistance in creating an automation that triggers based on values being equal to or between 2 numbers. I am using OpenWeatherForecast to pull the precipitation probability (sensor returns % - sensor.openweathermap_forecast_precipitation_probability). I would like to create an automation with a trigger that is:
"If sensor.openweathermap_forecast_precipitation_probability is between 10-50% (or equal to 10 or 50%) then...." - any help with this would be greatly appreciated!

mighty ledge
#

and what tinkerer wrote didn't work?

#

it's pretty much a copy/paste into a template trigger.

inner mesa
#

Meh, why try when you can just repeat the question

icy ravine
#

I did try, Rob. It is failing for some reason so I figured I would ask here if anyone had input.

inner mesa
#

Then I would start with what didn't work

marble jackal
#

Probably because it is currently alreadye between 10 and 50, triggers have to become true to trigger, they won't trigger if they are already true

icy ravine
#

Ah that makes sense, so I then tried pasting the template as a condition (just for testing) and it did return that it is valid and true - so I assume that if the value were to drop to 9% and then come back between 10-50, it would trigger?

mighty ledge
#

basically it needs to resolve false at one moment

#

then resolve true the next

icy ravine
#

Sweet, thanks guys! I've never used a template trigger before so this is all new to me! lol

mighty ledge
#

it'll only fire when the resolution changes from false to true, not true to true, etc

#

if you want it to resolve true -> true, you have to get inventive

marble jackal
thorny snow
#
service: notify.mobile_app_phone_2
data:
  title: >-
    {% set lock_status = trigger.to_state.attributes.lock_status %}
    {% set lock_status = lock_status|replace(" by RF", "by Home Assistant") %}
    {% set lock_status = lock_status|replace(" by Key Cylinder or Inside thumb turn","") %}
    {% set lock_status = lock_status|replace(" by user 0", "") %}
    {% set lock_status = lock_status|replace("user 1", "Joe") %}
    {% set lock_status = lock_status|replace("user 2", "Chance") %}
    {{ trigger.to_state.attributes.friendly_name }}
    {{ lock_status }}
  message: TTS
  data:
    channel: alarm_stream
    priority: high
    ttl: 0
#

Hi All.... this stopped working recently, and I don't know why.

#

I am on 2021.5.4 Docker/supervisor

#

I didn't update, and nothing seems to have changed. I get an error saying "PLEASE SET A TITLE FOR TEXT TO SPEECH TO PROCESS"

#

When I look in the variables section of the trace, the variables are all there (to_state.attributes etc)

inner mesa
#

You probably updated to iOS 16

dull burrow
#

That’s an old version

inner mesa
#

And yeah, that

thorny snow
#

Not on IOS

#

ANd yes, I am on 2021.5.4

dull burrow
#

Bad boy

thorny snow
#

Well, if it works.......

#

I don't muck with it

dull burrow
#

You really went for the S in IoT security lol

thorny snow
#

Sure

#

I also didn't code HA πŸ™‚

dull burrow
#

But you’re expecting help from a version with a shitload of known bugs

thorny snow
#

Is one of the known bugs that templates that worked for a year suddenly stop working?

dull burrow
#

With you being that far behind you can’t make any assumptions about what should be working correctly

thorny snow
#

The presumption is that if nothing changed, it should still work the same.

icy ravine
#

That is a valid presumption, but unfortunately that is often NOT true in the case of technology.

thorny snow
#

Ok, I feel sufficiently chastised. Any help with the template?

odd maple
#

the TTS bit has changed in the app

thorny snow
#

Ah, that makes sense.

#

So the App is barking about the TTS, not HA coughing.

thorny snow
#

That's got me in the right direction. Thank you!

odd maple
#

might work might not due to the older HA, but give it a shot

thorny snow
#

Yeah.. I may have to give up on these notifications or update my ZWave finally :/

mighty ledge
#

are you on the old zwave?

odd maple
thorny snow
#

Yes... the reason I am still on 2021.5.4

odd maple
#

the old zwave sucks πŸ˜›

mighty ledge
#

ouchies

thorny snow
#

I am sure. Updating it all sucks more right now.

mighty ledge
#

it's not tooooooooo bad

#

but it's completely different for the most part

#

as for your template, no clue why it stopped. can you post the real error?

#

and possibly a line or 2 before it

#

not the abbreviated Stolid error

thorny snow
#

LOL I think it's the App complaining about the old TTS format. That makes sense. I only get an audible error, from what I have seen...

mighty ledge
#

Ah

#

Ok

odd maple
#

ya the new tts_text field for the updated app

#

might fix it

thorny snow
#

Yeah, no errors at all.

mighty ledge
#

that's an odd situation

#

I'm not sure what would work

#

sounds like it's time to................... update

#

While you may not want to, the new zwave integration is worlds better than the old one

#

WORLDS

#

Things work, it's odd.

#

But, it can be confusing

thorny snow
#

What I have currently works basically perfectly... I haven't found the time to break it in order to upgrade.

#
  - service: notify.mobile_app_phone_2
    data:
      message: TTS
      data:
        tts_text: >-
        {% set lock_status = trigger.to_state.attributes.lock_status %}
        {% set lock_status = lock_status|replace(" by RF", "by Home Assistant") %}
        {% set lock_status = lock_status|replace(" by Key Cylinder or Inside thumb turn","") %}
        {% set lock_status = lock_status|replace(" by user 0", "") %}
        {% set lock_status = lock_status|replace("user 1", "Joe") %}
        {% set lock_status = lock_status|replace("user 2", "Chance") %}
        {{ trigger.to_state.attributes.friendly_name }} {{ lock_status }}
        media_stream: "alarm_stream"
#

I am going to attempt this when I get home to test the lock.

vocal agate
#

hello again i have two helpers saving times, as example 6:42Am and 4:40pm i want to create an entity showing the resulting duration.
http://pastie.org/p/31cke2EWC4hkmkiwlPGD07 but the sensor still unavailable... Anybody has an idea?

mighty ledge
#

from a screenshot in the developer tools states page. Do not copy/paste it here.

#

@vocal agate can you send a screenshot from the developer tools -> states page, not the history tab

vocal agate
#

send it in private

mighty ledge
#
workingtime:
        friendly_name: "AZ"
        value_template: "{{ (states('sensor.arbeit_start') | today_at - states('sensor.arbeit_ende') | today_at).seconds / 60 }}"
vocal agate
#

its stays unavailable

mighty ledge
#

what does it show in the template editor?

#

are there errors in the logs?

vocal agate
#

ValueError: could not convert str to datetime: 'unknown'

#

maybe it is because german international time format?

mighty ledge
#

ok, so you're restarting and the sensor doesn't have a time on startup

#
workingtime:
        friendly_name: "AZ"
        value_template: >
          {% set start = states('sensor.arbeit_start') %}
          {% set end = states('sensor.arbeit_ende') %}
          {% if 'unknown' not in [ start, end ] and 'unavailable' not in [ start, end ] %}
            {{ (today_at(start) - today_at(end)).seconds / 60 }}
          {% else %}
            none
          {% endif %}
#

if they are input_datetimes, just

#
workingtime:
        friendly_name: "AZ"
        value_template: "{{ (states('input_datetime.arbeit_start') | today_at - states('input_datetime.arbeit_ende') | today_at).seconds / 60 }}"
vocal agate
#

this seems to work

#

but the value gives 897

mighty ledge
#

well it is in minutes

vocal agate
#

so divide by 3600^^

mighty ledge
#

if you want hours, yes

vocal agate
#

but divided by 3600 it gives 14,95

#

it should be around 9

mighty ledge
#

working for me

#

with your numbers

#

is your timezone set correctly?

vocal agate
#

to german time yes

mighty ledge
#

what does {{ today_at() }} return in template editor?

#

what does {{ now().tzinfo }} return?

vocal agate
#

the funny thing is when i substract to timestamps from the inputdatetimes and divide it by 3600 the result is 9,05

#

2022-09-26 00:00:00+02:00 Today at

#

Europe/Berlin

mighty ledge
#

makes no sense why it's not working.

#

sure you don't have them reversed?

#

because start - end is 9.05, but end - start would be 14.95

#

if the start of your day is before the end, then you should be subtracting start from end, not end from start

#
value_template: "{{ (states('input_datetime.arbeit_ende') | today_at - states('input_datetime.arbeit_start') | today_at).seconds / 60 }}"
vocal agate
#

i copy pasted. πŸ˜„

#

of course now it is working properly

#

simple math is to much after a 9 hour work day

#

but however, after updating the sensor it stays unavailable

#

do i need the convert the values to integer?

mighty ledge
vocal agate
#

i think i need to reinitialize the sensors.yaml

#

now the sensor shows correct data. Thanks for your assistance petro

#

could you suggest a course to learn the language of Hass or it is learning by doing?

mighty ledge
#

uh, learn by doing... i guess

#

really not many resources to learn jinja unfortunately

marble jackal
#

and ask questions here

mighty ledge
#

πŸ€·β€β™‚οΈ

#

I wish there was something better

open hound
#

😐 Interesting.

#

I'm also having the issue with a sensor of mine that is blank.

#

It works fine in the template editor.

#

But doesn't work in my sensor.

#

I created a sensor that subtracts time off my son's school schedule.

#

And compares that to real time to determine what he should be doing prior to going to school.

#

(For instance, start getting ready an hour before school starts)

#

But while it works perfectly fine in the template, and will give me the proper value for what the state should be...

#

The sensor remains blank.

marble jackal
#

.share the code of the sensor @open hound

dusty grailBOT
#

@open hound Please use a code share site to share code or logs, for example:

Please don't use Pastebin, since it can randomly add spaces to the main view. Please also don't share text as images since it makes it harder for people to help you. Remember that others may have colour blindness, impaired vision, etc.

tacit sun
#

I have a roku device that never "turns off"... but, I want to use it's status as presence, is there a way for me to make a binary sensor where active app home = off and any other active app = on?

#

so far, what I'm trying is: Create an input_boolean.
Create an automation to set the input_boolean on state change of the roku. seems to work good enough...

Is there a better way, or is this a good method?

open hound
open hound
#

Meh... my logic was stupid. 😐

#

Now it says "Nothing" like it should.

#

I'll just have to come up with a way to get it so it doesn't register every single minute as a state change. It causes my automations to go nuts. 😐

marble jackal
#

I don't understand some of the choices you made here

#

And it looks like you are comparing a string and a datetime

#

Ah no, skip that last comment

#

But now() is already in local time

#

And even if it was not, you can compare datetimes in different timezones

#

{% if states('sensor.startGettingReady') != "Nothing" %} this will never be true, entity_ids are lowercase

open hound
#

I removed the comparisons to "Nothing."

#

😐

#

I realized they'd never evaluate to true for a different reason.

#

It was contradictory to logic.

#

But I didn't know about the entity_ids only being lowercase.

marble jackal
#

Well, actually it would always be true

hasty basin
#

anyone have any example of a sensor template for the average of a sensor value over the past X days?

example, average humidity in a room over 7 days. i'm seeing some mention of history stats but not clear how it should look

marble jackal
hasty basin
#

@marble jackal that one looks like it will work, thanks!

open hound
#

There. I have a revised version, that should work.

#

(Since it checks every minute (as it uses now() ), I had to add checks to keep it from assigning a state to it if it already has one assigned). 😐

#

Otherwise, it will keep re-writing the state, and falsely triggering other automations every single minute (as they check for state_changed triggers) 😐

#

I'll just have to check it tomorrow to make sure it is working all right. πŸ‘

#

Thanks for the eyes πŸ‘€ @marble jackal

sacred sparrow
#

does this look right? {{ state_attr('media_player.nest_mini', 'volume_level')|float != states('input_number.nest_default_volume_level')|float / 100 and not state_attr('media_player.nest_mini', 'volume_level') == none }}

inner mesa
#

Is the volume_level ever none?

sacred sparrow
#

when the nest is off yes

inner mesa
#

The template will fail when that happens

marble jackal
#

Move that check to the first position

#

And use state_atrr() is not none

azure drum
# marble jackal Move that check to the first position

Goedenmorgen, sorry to bother you again. I did some reading in the developers corner. The description of the statistics of sensor entities suggest, that it could be possible to handle min/max data. Since your little template just works perfectly, I was wondering if you would be willing to refine it in a way, to use the statistic functions? As far as I understand min/max values are stored if it is e.g. a measurement. How about the long-term-statistic? https://developers.home-assistant.io/docs/core/entity/sensor So, if that data is there, we would need a template that extracts the maximum or minimum state or native value, together with the datetime. What do you think? Possible?

marble jackal
#

jinja templates don't have access to the statistics data

#

and I haven't eaten cheese of python πŸ˜‰

azure drum
sacred sparrow
#
states('input_number.nest_default_volume_level')|float / 100 }}``` ?
verbal veldt
#

can anyone give me a hint how to best debug a mqtt sensor where the template is somehow wrong but I can not figurre out what

marble jackal
marble jackal
dusty grailBOT
ionic dagger
#

Hello - I hope theres a jinja-ninja-guru soul in here, that can help me with my template
I am trying to get a script working, that will give me the most expensive time periods of the day.
I would like to use it to control my heatpump. The best way to do it, from a heatpump pov, is 2 x 3 hours of shutdown, with a minimum of 6 hours in between.

This fits with the usual wave-high of electricity prices in the morning and evening.

A kind soul on the forums has helped me with the first timeslot, and I have been trying to engineer a way for a 2nd timeslot - but my attempts have failed as of this far.

See the hastebin for the code

ionic dagger
#

I have tried doing for loops and if statements, so that I could compare the results one by one, but I must achknowledge that my jinja skills aren't good enough for the task.

The code gives a list of summed prices for all the 3 hour windows of the day, so the data is there - I just have a hard time finding the result that is;
The largest value, that is also more than 6 hours from most_expensive_hours value

half pendant
#

I have a couple of heaters and i’d like to make a template that reports their state. Like if all are heating it should say ”All Heating” but if only one is on and the other two are off it should say ”Master Bedroom Heating” (name of heater + state). If can probably coble it together using a lot of if and else statements but wondering if there’s a smarter way to do it.

verbal veldt
#

not without seeing the template

marble jackal
#

first step I would suggest is to put them in a group, eg group.heaters

{% set heaters = expand('group.heaters') %}
{% if heaters | selectattr('state', 'eq', 'heating') | list | count == heaters | list | count %}
  All Heating
{% elif heaters | selectattr('state', 'eq', 'heating') | list | count == 0 %}
  None Heating
{% else %}
  {{ heater | selectattr('state', 'eq', 'heating') | map(attribute='name') | join(', ') | replace(',',' Heating,') ~ ' Heating' }}
{% endif %}
half pendant
#

Great! That will get me started! Will experiment with that and see what i get!

autumn matrix
#

Is here the place where I can ask a question about lambda usage in esphome?

marble jackal
dusty grailBOT
small rock
mighty ledge
# small rock How can I add a value to a array? https://hastebin.com/ejakuqurim.csharp
{% set ignore_entities = [] %}

{% set entities = states.sensor
  | selectattr('attributes.device_class', 'defined')
  | selectattr('attributes.device_class', 'eq', 'battery')
  | rejectattr('entity_id', 'in', ignore_entities)
  | selectattr('state', 'is_number') %}

{% set ns = namespace(entities = []) %}
{% for entity in entities if entity.state | int < 30 %}
  {% set ns.entities = ns.entities + [ entity.entity_id ] %}
{% endfor %}
{{ ns.entities }}
half pendant
#

How do i change so that the else diplays the attribute hvac_action next to their names instead of a generic ”heating” in this sensor

{% if heaters | selectattr('state', 'eq', 'heat') | selectattr('attributes.hvac_action', 'eq', 'idle') | list | count == heaters | list | count %}
  Radiators Idle
{% elif heaters | selectattr('state', 'eq', 'heat') | selectattr('attributes.hvac_action', 'eq', 'heating') | list | count == heaters | list | count %}
  Radiators Heating
{% elif heaters | selectattr('state', 'eq', 'heat') | list | count == 0 %}
  Radiators Off
{% else %}
  {{ heaters | selectattr('state', 'eq', 'heat') | map(attribute='name') | join(', ') | replace(',',' Heating,') ~ ' Heating' }}
{% endif %}```
mighty ledge
#

what

proven fog
#

I'm creating Template sensors for areas in my home. So, count all the lights on, count all the doors open, etc. for each area.

- sensor:
      - name: "All Kitchen Lights On"
        state: >
          {{ expand(area_entities('Kitchen') | select('match', 'light')) | selectattr('state','eq','on') | list | count }}

- sensor:
      - name: "Kitchen Doors Open"
        state: >
          {{ expand(area_entities('Kitchen') | select('search', 'door')) | selectattr('state','eq','on') | list | count }}

I'm wondering if it's best practice to combine these into a single sensor per room

#

Eventually it will be Lights, Doors, Windows, Devices

half pendant
mighty ledge
#

yep

#

are you referring to the ~ ' Heating'?

half pendant
#

Basically the last else statement displays the heaters that are turned on but it just says the name of the heater and a generic heating. I would like to change it so that it displays the name of the heater + whatever is in the attribute.hvac_action at the time

mighty ledge
#

But they are all heating based on the selector

half pendant
#

The state can be heat of off, but the hvac_action can be heating or idle

mighty ledge
#

ah, i see.

#

you'll have to do a for loop and drop the map

slim elk
#
{% set heaters = expand( ['climate.master_bedroom', 'climate.adina_bedroom'], ['climate.isac_bedroom']) | selectattr('state', 'eq', 'heat') | map(attribute='entity_id') | list %}
{% for heater in heaters -%}
{{ state_attr(heater, 'friendly_name') }} {{ state_attr(heater, 'hvac_action') ~ " " }}
{%- endfor %}
slim elk
#

can likely be cleaned up, but maybe a starting point

mighty ledge
#

you're mapping the state objects to list of entity_id's then you get the states from the state machine after you already had the state objects

slim elk
mighty ledge
#

state objects contain the state and attributes

half pendant
#

Id like it to work with the rest of the sensor

mighty ledge
#
{% set heaters = expand( ['climate.master_bedroom', 'climate.adina_bedroom'], ['climate.isac_bedroom']) %}
{% if heaters | selectattr('state', 'eq', 'heat') | selectattr('attributes.hvac_action', 'eq', 'idle') | list | count == heaters | list | count %}
  Radiators Idle
{% elif heaters | selectattr('state', 'eq', 'heat') | selectattr('attributes.hvac_action', 'eq', 'heating') | list | count == heaters | list | count %}
  Radiators Heating
{% elif heaters | selectattr('state', 'eq', 'heat') | list | count == 0 %}
  Radiators Off
{% else %}
  {% set ns = namespace(values=[]) %}
  {% for h in heaters | selectattr('state', 'eq', 'heat') %}
    {% set ns.values = ns.values + [ h.name ~ '(' ~ h.attributes.hvac_action ~ ')' ] %}
  {% endfor %}
  {{ ns.values | join(', ') }}
{% endif %}
#

or you can use groupby

inner mesa
#

Sounds like some radiator-based version of the 12 days of Christmas

mighty ledge
#

if yes, you can simplify that

#
{% set groups =  expand('climate.master_bedroom', 'climate.adina_bedroom', 'climate.isac_bedroom') | groupby(attribute='attributes.hvac_action') %}
{% if groups | length == 1 %}
  Radiators {{ groups[0][0].title() }}
{% elif groups | length > 1 %}
  {% set ns = namespace(values=[]) %}
  {% for k, values in groups %}
    {% set ns.values = ns.values + [ k.title() ~ ': ' ~ values | map(attribute='name') | list | join(', ') ] %}
  {% endfor %}
  {{ ns.values | join(' | ') }}
{% endif %}
half pendant
half pendant
mighty ledge
#

... is that what you want?

half pendant
#

Yes! The ( was unnessecary but i could fix that. Thank you!

#

Maybe if i can get the attribute capitalized? I

#

Heating vs heating

mighty ledge
#

.title()

half pendant
#

Worked with just | title

peak lynx
#

I've the following sensor that sometimes produces unwanted spikes:

- sensor:
    - name: "kamstrup totalt forbrug stat" # total usage for energy tab
      availability: "{{ states('sensor.kamstrup_kwh') | float > 1000 }}"
      unit_of_measurement: kWh
      state: "{{ states('sensor.kamstrup_kwh') }}"
      attributes:
        device_class: energy
        state_class: total_increasing

I have tried editing the values in the developer tools > statistics page, but the history and energy tab doesn't respect the new values. Does it have something to do with how I defined the sensor?

marble jackal
#

Your sensor will show the exact same state of sensor.kamstrup_kwh unless that sensor is below 1000 (or when it is not having a numeric state, eg when it's unavailable)

#

Does this source sensor reset on a daily/weekly/whatever basis?

odd osprey
#

Hello I have setup a sensor with Tasmota and yould like to invert the state of this Tasmota switch in Home Assistant. This is my sensor:

binary_sensor:
# Sensor Tasmota Heizung/Brenner
- name: "Heizung Brenner Status"
unique_id: "heizung_brenner_status"
state_topic: "tele/Brenner/SENSOR"
value_template: "{{ value_json.Switch1 }}"
icon: mdi:fire

peak lynx
#

But it not being a statistics sensor means I cannot edit the source sensor

#

Could I add state_class: total_increasing to the modbus source sensor?

      - name: Kamstrup kWh
        unit_of_measurement: kWh
        address: 8267
        slave: 1
        device_class: energy
        scale: 0.001
        precision: 2
        count: 2
        data_type: int32
ornate sundial
#

Hi all, this may fall under automations but I think my issue will be more to do with the formatting of the yaml. I have been trying to implement a script and automation originally created by Speek to the Geek article, https://www.speaktothegeek.co.uk/2022/04/money-saving-automations-1-heating/ but I am having issues with the script side of it. When I change the temperature thresholds in the input number helper and adjust the date to summer I expect the thermostat to switch to off however it just stays on eco. Looking at the traces for the script, it is definitely that which is causing the problem. I have linked my current yaml here for reference and would be very greatful.for any suggestions anyone may have, https://pastebin.com/uCxzyuhf -script
https://pastebin.com/76PYye2K - automation (that calls the script). Current forecast high and low is 15 and 5 degC with my set thresholds at high 30 and low 20. Winter date starts at 25th October.

barren jungle
#

Is there a function to grab entity_id or state by unique_id ?

#

That would be helpful to bind my template entities to specific device entities
(better then through device id that is auto generated it)

marble jackal
peak lynx
# marble jackal I don't understand your availability template then

Sometimes the meter fucks up and shows 0-3 kwh for a split second and then goes back to the total consumption for the house since we moved in. I need to filter out these values, which is what I tried with the availability condition. We are currently up to 8k kwh, so I just put in 1000 to be safe.

open hound
#

Quick question... I am running into a template loop issue. Can self-referencing the state in a comparison cause that?

#

Basically, the sensor updates every minute (due to using now() )

#

However, it has a state assigned to it from the previous iteration.

#

I am wanting to do a comparison that stops it from assigning the same state to the sensor, if it already has that state.

marble jackal
#

maybe that is causing the spikes

marble jackal
#

to not assign a state, you would need to have conditions like in automations, there is a feature request open for that on the forum

#

vote for it if you want πŸ™‚

open hound
#

It was referring back to the yaml templating I was working on earlier.

#

Where I was creating a custom sensor. (Still debugging it)

#

Finally figured out how to get it so the sensor wasn't blank (or null) by assigning an initial value...

#

Well... an if state that says that if it is blank, give it a value.

#

And hopefully, the state changes properly when it hits my schedule for it.

#

The goal of my sensor was to give a custom state to it at a certain time before an event (my son's school starts).

#

So, an hour before school starts "Start Getting Ready"

#

25 minutes before school starts "Wait for Bus"

#

Etc.

#

I use the state of the sensor in a Node Red flow to trigger events to happen.

sacred sparrow
#

when I do this:

target:
  entity_id: media_player.nest_mini
data:
  volume_level: "{{ states('input_number.nest_default_volume_level')|float / 100 - 0.04 }}"```
the volume changes to 0.7099999785423279
instead of 0.71
input_number.nest_default_volume_level = 75
marble jackal
sacred sparrow
#

{{ states('input_number.nest_default_volume_level')|float / 100 - 0.04 }} shows up as 0.71 so I am not sure why it doesnt work when setting volume

marble jackal
open hound
#

Because it repeating the same message through tts every single minute is annoying. 😐

#

But, I've done it before... I'll just do it again. (Just not as elegantly)

marble jackal
marble jackal
#

what do you use for the TTS?

open hound
#

google cloud

sacred sparrow
#

ah that makes sense - thank you πŸ™‚

marble jackal
candid nacelle
marble jackal
#

make sure it triggers on on actual state changes, not on attributes or whatever

marble jackal
open hound
#

Yeah, I am not using an automation with it.

marble jackal
#

Why would it send a TTS every minute then?

open hound
#

Not sure, something with Node Red (which I'll figure out there).

marble jackal
#

that's also an automation then (in the broader sense of the word)

open hound
#

As of right now, I finally got the sensor so it isn't null.

marble jackal
open hound
#

And hopefully, with the checks I put in place, I don't start getting the same state tacked on to itself.

#

(I have a state of "Nothing") when there is no event going on.

#

And for a while there, I was getting "Nothing Nothing Nothing" because it kept appending Nothing onto itself. 😐

#

(So, hopefully, the additional checks prevent that from happening)

open hound
#

Yeah, now, if the state is already Nothing, and the state isn't supposed to change, then no state change.

#

So, I'll just have to check and make sure that is working later on (when it is time for my son to go to school again)

#

And then to my next project... scraping data off of Tuya's IoT debug pages. 😐

#

Because I will not rest until I get my door/window sensor to work within Home Assistant without having to read notifications off of my phone. Too unreliable.

#

And while the door window sensor integration is non-functional in Home Assistant... the debug logs do update when the sensor is triggered. 😐

#

Within the IoT on Tuya's site.

#

Anyways, 4:55 AM here. I'm off to bed.

elder moon
#

why this template doesnt work (errors):
{% if ((trigger.event.data.entity_id == 'sensor.ebusd_bai_currenterror_error') OR (trigger.event.data.entity_id == 'sensor.ebusd_bai_currenterror_other_error')) %}
while this works fine:
{% if (trigger.event.data.entity_id == 'sensor.ebusd_bai_currenterror_error') %}

inner mesa
#

Your 'OR' should be 'or'

#

Always state what errors you're seeing, don't just say '(errors)'

elder moon
#

ahh thanks!

marble jackal
#

@elder moon You could also use {% if trigger.event.data.entity_id in [ 'sensor.ebusd_bai_currenterror_error', 'sensor.ebusd_bai_currenterror_other_error'] %}

jagged totem
#

Anyone know how to get the number of days in the current month?

marble jackal
#

you mean 30 for this month for example?

jagged totem
#

ye

#

something(now(), "last day of the month") πŸ˜„

floral shuttle
#
        state: >
          {% set month =  now().month %}
          {% if month in [1,3,5,7,8,10,12] %} 31
          {% elif month in [4,6,9,11] %} 30
          {% else %} {{'29' if states('sensor.year')|int//4 == 0 else '28'}}
          {% endif %}``` although some comments have been made in the past this will derail in 70 years....
marble jackal
#

{{ ((now().replace(day=1) + timedelta(days=31)).replace(day=1) - timedelta(days=1)).day }}

jagged totem
#

nice, that is what I saw for python just could not find the right jinja things πŸ‘Œ

dull burrow
#

Do you guys think there will be a more noob friendly way to do advanced automations and templating if we don’t have calculator brains like thefes?

mighty ledge
#

nope

dull burrow
#

Some of the shit you guys come up with here is wild

mighty ledge
#

time is hard, no matter what way you look at it

#

the problem is, there's 1000s of wrong examples on the forums that people just use

dull burrow
mighty ledge
#

no, its a life lesson about dealing with time across all timezones

jagged totem
#

I was/am generating a rough electricity consumption forecast

{% set hours = (now().day * 24) + now().hour %}
{% set consumption = states('sensor.energy_month') | float(0) %}
{% set maxHours = (((now().replace(day=1) + timedelta(days=31)).replace(day=1) - timedelta(days=1)).day) * 24 %}
{% if consumption > 0 %}
{{ ((consumption / hours) * maxHours) | round(2) }}
{% endif %}
mighty ledge
#

there's a whole time thread on the forums...