#The Bates Motel

1 messages · Page 1 of 1 (latest)

empty forum
#

Anyone can do it

#

Norman

terse grove
#

Just reply in here

#

@weak fossil

weak fossil
#

ok

#

so this is my current code

#

well petros code mostly just fixed a few things and commented out for my self to be able to grasp it

#

got it to the point it works when i close a window (the first choose condition in the actions)

#

but the second condition when i open a window doesnt work yet

terse grove
#

The delay condition needs to move before the condition. If it needs to execute before the check.

#

Back where I it originally was

weak fossil
#

ok, let me see

#

but regardless of that the secdond scenario is not executing (closing a door works, opening a door just doesnt trigger based on the trace steps)

terse grove
#

It won’t if nothing has been on over the duration

#

I don’t know how else to explain that to you

weak fossil
#

ok gotcha

terse grove
#

It’s counting all sensors that are on for the specified duration. If they aren’t on, it won’t trigger.

weak fossil
#

do you need to count the time? im my code i just waited the delay and after just checked if still open then i executed

terse grove
#

Check your code again, every room counted the last changed against the door or window duration. I just copied it and optimized it

#

You can certainly remove that portion, I just tried to maintain what you had

weak fossil
#

i dont think i ever checked again for that

terse grove
#

It didn’t make sense to me why you were doing that

weak fossil
#

i just made sure they where still open

terse grove
#

Post your old code, I’ll point out the line.

weak fossil
#

soory wrong link

#

i have several following the same format

#

im gonna nedd to port your example over im in for a ride 😭

terse grove
#

224 to 231 check the last changed vs the duration

#

Specifically 227 and 230 that do the calc

weak fossil
#

ohh yeah, your good petro, lol, ok you are right, I recall it was to avoid if people open and close the door several times befoire the delay elapses that the AC will shut off

#

as its a parallel automation

#

so how should i write it for it to make sense as before

terse grove
#

Personally, if I was in your situation, I’d learn blueprints and avoid the state changed event

#

Make a blueprint that you can understand that works for 1 room. Then use the blueprint to create all the automations

weak fossil
#

the thing is petro i wanted to avoid all this, all i wanted to get rid of some simple warnings in my logs, and again i get down this rabbit hole, i posted a few weeks back i was willing to hire someone to do this for me, upgrade the code to fix breaking changes and that was pretty much it, 3 years back i had time, we had 2 babys since then and its becoming hard for me to keep up with everything, this week allready has been to much for me personally, and relly all i wanted to to is upgrade an old intall running and very out of date supervised raspian to fix vulnerabilities and migrate to HAOS so its easier to keep ht OS up to date and fix the breakingchanges and now im in this rabbit hole again

#

but regarless now im in it so at least i would like to learn something from your code

#

they recommended me posting in the social section of the forums but i read some threads and didnt look like people where to willing to be hired to do this so i tough i would give it a shot

terse grove
#

Well some people shun against it for some reason

#

You can ignore them if you want

weak fossil
#

if you know anyone good that is open to be hired let me know please

#

but for now lets fix this template as i allready have invested to much time and at least i will learn something from it

#

idealy the code should be writtren from scrath taking adavnatege of all the new posibilities that currente releases offer

#

but my old code altough ugggly works 100%

#

and its not a motel but it is installed in a rental property i have 200 miles away and i cant afford to break anything, that is why im replicating it on another clean intall at my home so i can just swap over one for another

#

all this comes from some mallware that got speaded trough that house and i suspect also infected the rpi that is running the 3 year out of date rapian in that location

#

mallware i could not get rid of even factory reseting the phones its on

#

its been a nightmare

weak fossil
#

i just dont have time to re-write everything from scratch, or learn how to do it, again i allready told you im a highschool dropout, i like this stuf and i can figure it out but it takes me ages

#

i love engeniring but dont have formal education in it

#

so if we can fix this template maybe if i get to understand your code and then it i can port it to my other automations for the time being

#

i kind of follow along allready but dont have the skills you guys have

#

anyway

#

but its not passing the config check

#

Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token 'end of print statement', got '=') for dictionary value @ data['action'][0]['choose'][0]['conditions'][0]['value_template']. Got None. (See ?, line ?).
Invalid config for [automation]: required key not provided @ data['action'][1]['choose'][1]['sequence'][0]['choose'][0]['sequence']. Got None. (See ?, line ?).

weak fossil
#

(to hire someone) rest of conversation is in the general chat

weak fossil
#

looks like im not gonna sleep tonight again, its 2 am need to wak up at 6

#

still banging my head on the wall

#

tipical me

terse grove
#
            # Only delay when turning off the AC and group is not home or off
          
            - choose:
                
                - conditions:
                  
                    - condition: template
                      #value_template: "{{ is_state(group, 'away') }}"
                      value_template: "{{ states(group) in ['not_home', 'off'] }}"
                  sequence:
                  
                  - delay: "{{ room_delay }}"   
#

all of that has to be moved first

#

how about this

#

tell me what you expect this to do because I'm just trying to replicate your code

#

and to me, most of the reasoning behind what was done didn't make sense

#

So I shrugged my shoulders and replicated the functionality.

#

and when I say didn't make sense, I mean, it didn't make sense logically

#

what's the intention behind auto_off and auto_on? Those switches seem meaningless

weak fossil
weak fossil
#
  • auto_on and auto_off boleeans control the functinality of this, if auto on is enabled every time tou close a door ac will switch on, if auto_off in enabled everytime you open a door or window it will waiut x time to switch ac off

  • enable_window_switch bolean enables/disables all this functionality completely in back end and also and aditionaly automaticaly removes it or ads it to from lovelave front end

  • auto_off should trigger only after the the set period of time set in the input_datetime for that room (delay) so if you open a door or a window it should take x time to switch ac off.

  • if auto_on enabled it should trigger instantly as long as group is home or on

  • Group needs to be either "home" or "on" for any of this to happen

  • The sense behing having auto_on and auto_off separate is because particular rooms have phisical acces to the sonoff i use to power the AC so i dont need them all to automaticaly switch on if presence is detected, as presence is detected in the house not per room basis

#

time should reset every time a door is open or closed, its what you very smartly pointed out before, as its parallel automations i found i needed to make sure the time set in the input_datetime had realy elapsed from last opening of the door

#

the code you put togueter prety much replicatd all that, the on funtion worked after a few tweaks but the auto off function with the apropiate delay i can seem to figure out how to code

terse grove
#

Ok, so why are you checking all that crap in the choose then?

weak fossil
#

because its the best i knew how to do back in the day and also from your guys advice

terse grove
#

ok

weak fossil
#

same as using state_change everyone pointed me in that direction and i even remeber coments of people in discord saiying that frenk though everything should be state_changed based

#

again HA has changes a lot

#

and i wanted this to be transparent and expandbale and that is the only solution anyone gave me back in the day

#

but forget about my old code, im trying to get yours to work, now that i kind of grasp it 80% it makes a lot of sense

#

idealy there is alot of other stuff i dont like how i had to do and this was a frustration back in the day with the limitations ha had 3 years ago

#

are you willing to be hired petro? I fell bad taking up your time for free

#

and clearly you can do this shit with your eyes closed 🫡

#

i have done most of the leg work just need a little help with the more complex stuff

#

i mean I have sorted all the breaking changes and updating HA etc but im not up to date with all new functionality etc and dont have time to learn it properly

#

pm me if you are open to it

#

🙏

weak fossil
#

i really dont get how ha yaml works, i removed all the crap i was testing and just left this (the code that worked and now it doesnt trigger) https://dpaste.org/fH9RY

#

is it imperative if you use choose to have more than one condition?

terse grove
weak fossil
#

Error loading /config/configuration.yaml: mapping values are not allowed here
in "/config/automations/Windows Automation Template Petro.yaml", line 4, column 16

#

it has all the corrections and my comment to follow along 😅

terse grove
#

when you copy from dpaste, are you copying the raw snipit?

#

if not, that's causing the validation errors

#

click the raw button and copy the raw text

#

the code is roughly the same, just moved around, you can add your comments back

weak fossil
terse grove
#

copy/paste the whole thing

#

don't try to piece meal it in to what you have

weak fossil
#

let me try a 4th time

#

nah it dosnt pass

#

Error loading /config/configuration.yaml: expected '<document start>', but found '<scalar>'
in "/config/automations/Windows Automation Template Petro.yaml", line 124, column 1

terse grove
#

that means you aren't clicking the raw button on dpaste

#

124 is a blank line

#

if you copy from dpaste, it adds odd carriage returns

#

you have to copy from raw

weak fossil
# terse grove the code is roughly the same, just moved around, you can add your comments back

Logger: homeassistant.config
Source: config.py:455
First occurred: September 18, 2022 at 8:11:54 PM (8 occurrences)
Last logged: 3:44:44 AM

Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token 'end of print statement', got '=') for dictionary value @ data['action'][0]['choose'][0]['conditions'][0]['value_template']. Got None. (See ?, line ?).
Invalid config for [automation]: required key not provided @ data['action'][1]['choose'][1]['sequence'][0]['choose'][0]['sequence']. Got None. (See ?, line ?).
Invalid config for [automation]: Unexpected value for condition: 'None'. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data['action'][1]['choose'][1]['conditions'][1]. Got None. (See ?, line ?).
Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected '}', expected ']') for dictionary value @ data['variables']['away']. Got None. (See ?, line ?).

terse grove
#

ah ok, that might be a bug

#

change away to

#
      away: >
        {{ state(group) in ['off', 'not_home'] }}
weak fossil
#

how the fuck are you so fast spoting errors?

#

yes that passed

terse grove
#

🤷‍♂️

weak fossil
#

ok give me a few to test it

#

again same crap:

#
      event_data:
        domain: binary_sensor

```
#

you really should have used my latest version

#

there wherw a bunch of error in your code

#

if you started from your original code i need to correct them all

#

sorry my bad i have 20 windows open give me a minute

terse grove
#

you actually broke it

#

when you added your input_datetime stuff

weak fossil
#

ii managed all the traces to make sense on my coide and all was looking out good

terse grove
#

yes but you hard coded it to the bedroom

weak fossil
#

i hate you

#

yes mostlikely yoyu are right because i tried trigering living room and it dind twork

#

but there was a bunch of other stuff i needed to correct alto

#

also*

terse grove
#

like what?

weak fossil
#

its all commented here on muy code

#

changes and everything

terse grove
#

just found some more bugs

weak fossil
#

i commented my changes to make it easy for you

#

read the comments

terse grove
#

merged

#

fixed crap

weak fossil
#

how th fuck are you so fast men?

#

you blow me away

terse grove
#

I've been coding for years, it's just second nature

weak fossil
#

i have no degree but im not stupind and have 3 screens

#

1 ultrawide and 2 on other side

#

i cant graspu your speed

#

its amazing

terse grove
#

must be nice, i'm a cheap ass and am running on a 13 year old monitor and a $100 cheap monitor

#

it's so old its plasma

#

not CRT, but still old

weak fossil
#

you really gave me a lesson about huimility last days

#

regardless of screens etc

#

i was so proud of what i had done

#

and here comes petro and fucks me up

#

in a good way

terse grove
#

ok, i think my monitor is from 2010

weak fossil
#

where you from?

#

give me a sec to check this

terse grove
#

ny

weak fossil
#

or a few mnutes rather

#

lol

terse grove
#

2008

weak fossil
#

ok your autoimation as is its not trigerring

terse grove
#

didn't change the trigger

#

post the changed variables in the trace

#

i added magic, need to see if it's working

weak fossil
#

yes well i found the same ting happening to me with errors in my test code that pass config check

#

and automation would not trigger

#

and baning my head for hours because of these things

#

there is no trace the automation did not trigger

terse grove
#

I don't see how it couldn't not trigger

#

it's just a state changed event trigger

weak fossil
#

you wanna screen share?

terse grove
#

sure share it

#

go to

weak fossil
#

giver me a secd headphones

terse grove
#

hangout

weak fossil
#

a8jcv6z3

terse grove
#

keep message

weak fossil
#

@terse grove sorry i have ben a llittle absent , i needed some time to work all this out, i think I manage to modify the scrpt you did for me and got it to a point where it works but im struggling with one last little pc of the puzzle

terse grove
#

Just post it in here

weak fossil
#

above is my full corrected code

#
condition: template
value_template: |
  {% if run_off %}
    {% set ns = namespace(result = []) %}
    {% for x in expand(room_sensors) | selectattr('state', 'eq', 'on') %}
      {% set lc = now() - x.last_changed %}
      {% if 'window' in x.object_id and lc.seconds > window_timer or 'door' in x.object_id and lc.seconds > door_timer %}
        {% set ns.result = ns.result + [ x.object_id ] %}
      {% endif %}
    {% endfor %}
    {{ ns.result | length > 0 }}
  {% else %}
    False
  {% endif %}
#

it breaks here, i need this condition to become true

#

basicaly its checking if any door or window is still open and if if yes if should continue

#

what is happening the window is still open but the script stops here and donestn continue and switch ac off as it should

weak fossil
#

Better said it needs to check it's still open after the period of time set in the delay, meaning if x minutes has passed since door has been opened for the last time it should become true and switch ac off

#

But i managed to modify the script so it waits the delay as intended but when it passes the delay portion and gets here it becomes false although the delay as already passed

weak fossil
#

@terse grove I just realized the condition becomes true only if there is more than one sensor on, (meaning when i open a second door or window it does execute and switch ac off)

terse grove
#

Can you post the script again? I don’t have it anymore

weak fossil
#

as i mentioned i think i have got everything, working its just the last template that only becomes true if there is 2 or more window opens, its should be true if any is open

terse grove
#

Yeah, that's not the problem

#

how are you testing it? The template checks all windows and doors and compares each window or door to window timer or door timer

#

if the door opens and triggers it, and the window delay is LONGER than the door delay, the window being open will be rejected.

#

that's how you had it coded in the past

#

you're checking to see if windows are open longer than their configured delay

#

and you have it separated between windows and doors

weak fossil
#

for checking delay is LONGER i have a separate window open with the template editor configured doing the same math your template uses and i can see it real time

terse grove
#

but the delay is based on the triggering entity, which is a window or a door. and that can lead to unexpected results

weak fossil
#

The thing is the template passes if there is more than 1 window open, but returns false if only one window or door is open

#

and the delay portion is also working fine and passing when i check the traces

#

also fyi both delays for window and door are set to the same value for testing purpuses

#

i have it set at 10 seconds at the moment for both

terse grove
#

Try this

#

then post the Changed Variables for the newly added variables step that further down in the script.

weak fossil
#

ok i tried that, replaced all the code for what you posted, but for some reason i reload the script and execute it and when i go to the inspector and check the traces if i go to script config where i can see the code I see its not reloading the new code its still executing the old version

#

i try to reloaded a bunch of times

#

not getting eny erors either when reloading script

#

very weird

terse grove
#

clear your browser cache

#

CTRL F5

weak fossil
#

same thing

terse grove
#

you must have 2 copies of the same script

#

replace your old script completely

#

don't try to make 2 scripts so you can keep the old one

weak fossil
#

no i dont, i replaced it completely

terse grove
#

then you should have errors in the logs or it should be updating in the scirpt window

weak fossil
#

just copied my old code to a new tab in notepad and replaced the content of the working file with your code

terse grove
#

and you saved the file after pasting?

weak fossil
#

i have been modifiend the script many times and this never happened

#

yes sure i saved it

#

i even whent to the folder and opened it again

terse grove
#

ok, and you're reloading scripts, correct?

weak fossil
#

like 10 times allready

terse grove
#

ok, then you should have errors in the logs or there should be new traces after you trigger it

weak fossil
#

Error loading /config/configuration.yaml: while scanning a simple key
in "/config/scripts/window_script.yaml", line 32, column 1
could not find expected ':'
in "/config/scripts/window_script.yaml", line 33, column 3

#

ok yes i dindt do a config check

#

wasnt complaining upon reloading

terse grove
#

whatever it is, it's the stupid invisible characters again

#

did you copy raw or did you copy without doing the raw?

weak fossil
#

i didnt

#

let me try i totaly forgot about thet

terse grove
#

try this one with raw

weak fossil
#

yes this one seems to load, the nprevious one didnt even in raw

#

give me a sec to run it

#
delays:
  - entity_id: binary_sensor.doorbr01a
    door: 10
    window: 0
    last_changed: 10
    disposition: false```
terse grove
#

is that it?

weak fossil
#

still fails

terse grove
#

is there only 1 sensor in that room?

#

there should be more.

weak fossil
#

that is the door i openend

terse grove
#

ah, forgot about the eq on

weak fossil
#

there are 2 doors and 2 windows

terse grove
#

anyways, I see the problem

#

change

#
                      {% set disposition = 'window' in x.object_id and lc.seconds > window_timer or 'door' in x.object_id and lc.seconds > door_timer %}
#

to

#
                      {% set disposition = 'window' in x.object_id and lc.seconds >= window_timer or 'door' in x.object_id and lc.seconds >= door_timer %}
#

FYI, your old script had this problem too. Not sure how the old one worked, unless seconds was a float, which would potentially make sense that it worked.

weak fossil
#

i cant tell you but 100% it was working flawlessly for almost 3 years

#

seems as far as i can tell for now your the last change did it

terse grove
#

and now you have all the information you need to debug things

weak fossil
#

yes its been really helpfull

#

both to understand your code and to fix a bunch of other stuff that wasnt right either, i just could figure this one out

#

ok now it makes sense, with 2 doors open i see the variables of both

delays:
  - entity_id: binary_sensor.doorbr01a
    door: 10
    window: 0
    last_changed: 123
    disposition: true
  - entity_id: binary_sensor.doorbr01b
    door: 10
    window: 0
    last_changed: 10
    disposition: true```
terse grove
#

using the delays variable, you should be able to see what timer it selects, door or window for each entity. The disposition is weather or not it's greater than the timer

#

yep, and a window will look like this assuming windows have a 15 second timer

#
  - entity_id: binary_sensor.window..
    door: 0
    window: 15
    last_changed: 1342
    disposition: true
#

the door attribute will be 0 because it's not a door

#

where the window will be filled with the window timer

#

this way, you can see all the things the code finds

weak fossil
#

correct

#

just tested it

#

just need to do some more testing to see if delays work as expected when having different values, but looks like all is good for now 🥰

#

thanks so much men!

terse grove
#

np

weak fossil
#

ahh there is more one thing i found

#

that is why i was using new and old state i believe

#

right now this automation triggers both when closing and opening windows

#

meaning i have 2 of them open , i close one and its still goes trough and sends the ac off signal

#

which i guess is not a big deal as ac is allrerady off

terse grove
#

you can add a condition to not turn it off if it's already off

weak fossil
#

but no worries about this i might be able to figure it out and i dont think it will affect funcionality

#

yes i think i had that implemented in my old code

#

ill get back to you if i cant figure it out, need to go now pickup my dautgher from the nursery, thanks again!

weak fossil
#

Your code is fantastic, been trying to break it and test all scenarios and it seems to work exactly as intended

#

There is one small thing I would like to improve, i didnt even bother to mentioned because i did a quick and dirty patch to solve it, but i guess i rather do it now than leave it like this

weak fossil
#

its this variable:

  groups:
    br: room
    lr: living
    kitchen: kitchen
  location: "{{ groups.get(sensor.room, 'unknown') }}"```
#

the "br: room" portion, you use it to set location and location is the input to my other script that I call to switch ac ON and OFF

#

problem is you also use it in other parts of the code so if i change it breaks

#

And my AC Switch script calls for bedroom instead of room

#

the way i fixed is i just made a copy of my AC script with a diferent name that takes room instead of bedroom as input, so bacicaly I have 2 scripts doing the same thing, one for your code and one for the rest of my other code 😅

terse grove
#
  something_else:
    br: foofoo
    lr: barbar
    kitchen: kkadjfklashdf
  some_other_location: "{{ something_else.get(sensor.room, 'unknown') }}"
weak fossil
#

gotcha

#

yes that did exactly what i wanted thanks

#

gonna need to learn how to use variables better

#

I have like half a dozen automations writen in the same stile and lenght as the first one you rewrote for me 🤦

#

One question i have been googling and i think the answer is still no:

#

have there been global variables implemented in HA?

#

because im currently using a lot of hacks like using secrets and input helpers to store variables i need across all HA, im wondering if it was ever implemented

#

im gonna take your example and see if i can build upon it with what you have teached me and migrate another of my automations

#

dont wanna boither you to much, you allready did enough for me so i will start asking questions on the template section

terse grove
weak fossil
#

I dont understanmd why we cant just have a page of global variables like any other programing language 😦 anyway im sure they are reasons but the helpers have their limitations (or at least had when i made my code)

terse grove
#

They are pretty limitless at this point, you just have to declare them before using them

weak fossil
#

anyway, let me continuing trying to replicate your code

#

using the same automation you created to call the script i want to call 2 scripts

#

buts its only calling the first one

#

as i basicaly need the sama data as your automation provides for my first script and the way you did it writing it as a script is really helpfull to debug traces

#

nada forget my last question if i put the same code on botrh scripts it calls both so i guess i need to take it from there

weak fossil
#

And it is kind of working, at least the first choose condition, but i cant get the second one to trigger, i know why but i cant figure out the best aproach to solve it

#

this is the automation trigger that calls the script

#

you will see i added another regex portion

#

problem I think is basicaly this, the first script we did togheter triggered only on binary_sensors named either window or door

#

but this new script i have made needs to both trigger on the same sensors + another input_boolean for the second condition in the choose portion

#

following a similar naming convention: input_bolean.reset_sensorsbr01 , input_bolean.reset_sensorskitchen02 etc

#

im trying to figure out the right aproach because of course when i trigger on the input_boleans the variables i have set up dont match anymore

#

im not sure how well i have explained myself

#

my best guess so far as a solution is i will have have to have 2 separate automations and 2 separate scripts, but maybe there is a better way

#

or maybe im completely wrong and its somethig else, also quite probable 😅

weak fossil
#

Hang on for now, i´m slipting it in 2 that that makes it simpler to read and also for me to understand, might need some help with modifing the regex to get the propper variables from my entidy ID 🙏

weak fossil
#

Ok here it is, could you just review the regex portion and the variables, I know its not right and that is really a little out of my knowlede for now, its not calling the script

Trigger automation: https://dpaste.org/DJ1j8
Called script: https://dpaste.org/TQ3na

weak fossil
#

i really hate to bother you, that is the thing of threads nobody except the people who participate in them look at them 😦

#

anywahy i think i figured out the regex:

#

with the template editor this outputs what i need

{% set searching = ( states.input_boolean.reset_sensorsbr01.object_id ) %}
searching= {{searching}}
{% set regex_result = ( searching | regex_findall('(reset_sensors)([a-z_]+)([0-9]{2})') ) %}
regex result: {{regex_result}}
{%- set s, r, n = regex_result | first | default(['', '', '']) %}
{{ {'name': s, 'room': r, 'room_number': n, 'id': r ~ n} }}
#

searching= reset_sensorsbr01

regex result: [('reset_sensors', 'br', '01')]
{'name': 'reset_sensors', 'room': 'br', 'room_number': '01', 'id': 'br01'}

weak fossil
#

found it hard to figure the regex out and everything else but it seems to work

#

so just to let you know the time you spent helping me is being put to good use 🥰

#

but struggling with some things still

terse grove
#

Sorry, was at work all day

weak fossil
#

no worries men i get it

#

i cant expect anyone to be here for me 24/7

terse grove
#

that regex should work

weak fossil
#

just reachiung out to you because you kind of know what im trying to do and can point out faults easy

#

yes it works 🙂

terse grove
#

Nice, the script is short too

#

just keep using that pattern and you should be good for all your crazy automations

weak fossil
#

i need to ask you one more thing, how can i improve, you made a comment before we crated the thread about the mistakes i did with naming etc

#

and i dindt quite understand

#

you want me to copy paste here or just @ you in the templates forum

terse grove
#

you had a few callouts that were looking at variables like 'switch_abc_on' but they were only declared as 'switch_abc'. You did that in a few places

#

if you're using the new automation, it's a moot point because the new automation doesn't have those issues

weak fossil
#

none of this lr crap means livingroom and living and living room
stick with 1 name
br = bedroom
lr = livingroom
kr = kitchen
if you did something like that and named everything in accordance to that it would be easier
also, if you had separated the identifiers out with _, you wouldn't need the fancy regex that I had to use
either way, that should work, but I can guarentee there are errors because i dont' have any of this stuff
you were constantly checking the same crap when you didn't need to
if you have the check in the beginning, it won't be needed in the middle
like the sensor name being door or window
you had that check everywhere
but it didn'tneed to happen in the middle of your script because that's not changing.

#

this statement

#

specificaly this

#

if you did something like that and named everything in accordance to that it would be easier
also, if you had separated the identifiers out with _, you wouldn't need the fancy regex that I had to use

#

and also idealy i would like to stay away from using state_change triggers

#

but back in the day they told me it was the only way to achieve what i wanted

terse grove
#

Oh, yea

#

If you uses the same letter combo for everything you’d be good to go and you wouldn’t need those maps

#

Like stick with br for all bedroom related entities.

weak fossil
#

what does separated the identifiers out with _, mean?

terse grove
#

instead of reset_sensorskitchen01, you have reset_sensors_kitchen_01

#

then you don't have to use regex

#

{% set a, b, c, d = 'reset_sensors_kitchen_01'.split('_') %}

#

a is reset, b is sensors, c is kitchen, d is 01

#

alot easier

weak fossil
#

ohh i see

#

yep makes sense would make my life easier, wasnt aware

terse grove
#

the downside is that you'd have to change the scripts around because regex is being used to populate the values with empty strings

#

if regex doesn't find a match, it fills with the defaults

#

so you lose that ability

#

and you have to come up with a different way to 'match'

#

basically, you have to weigh your options

weak fossil
#

just notes for the future, would be a nighmare to change, but if i had to do it now would be the best time as im re-writting everything

terse grove
#

that's an even bigger change

weak fossil
#

is there another way to achieve the same without using state_trigger (meaning scalability and transparency in the code to add or delete sensors) and if yes will it improve perfoirmance in any way?

terse grove
#

there is, but it requires you to create dynamic groups and then fire off entities in the groups

weak fossil
#

kind of what thefess proposed? give me a sec to look it up

#

go to templates i quoted last message and read what he proposed

#

is that the same you are proposing?

weak fossil
terse grove
#

yes it is like his approach

#

you'd create an automation that fires on startup that gathers all sensors in a room and puts them in a group

#

then you create a templte sensor that counts the number of sensors that are on in the group

#

the automation that controls the doors and windows will now be based on the counting sensor instead of state changed events

#

Your condition will be that the count is greater than zero.

#

you can add a trigger id to the sensor so that you know which room is triggering

weak fossil
#

@terse grove can you check this out?

#

this works fine

#

can you think of a reason this would happen or am i doing something wrong?

terse grove
#

looks correct

#

Do you have all these automations running or did you turn off the other ones?

weak fossil
#

no its not running, i just add kk after the filename: filename.yaml kk

#

and reload automations of course

#

ill try again, its really weird, maybe i meesed up something 🤷

terse grove
#

you might actually be hitting the max parallel value

#

and your system might not be able to handle that many scripts running

#

it's hard to say

weak fossil
#

funny its exactly what i changed now

#

lol

#

put 100k as max value

terse grove
#

that's why thefes suggested moving away from state_changed events

#

you can try that but your system may still freeze

weak fossil
#

i counted yesterday i have around 2700 events fired per minute

#

actualy posted in the templates section

#

but this is a short automation and will fail most of the time unless its one of those sensors triggering it, im not sure it can hit the max parallel value

weak fossil
weak fossil
#

@terse grove

I had to backtrack and restore a backup and continue from there,

Issue I have is im still having the same problem that i wanted to sort then all this started with (warnings in the logs, just now its a lot worse than before LOL)

#

I must have fucked up something that made the system freeze

#

i have a small question now, im trying to make all the sanity checks in the script automation call

#

my quesiton is im trigering the above with with binary_sensor.doorbr01a and both the chose conditions are becoming true

#

the other binary sensor is binary_sensor.doorbr01atamper

#

so if its the first one that triggers i want the first condition to become true, and if its the second i want the first condition to become false and second condition to become true

#
        - conditions:
            - condition: template
              value_template: "{{ 'tamper' not in searching}}"```
#

is this not right to filter the above?

#

toghether woth the opossite:

        - conditions:
            - condition: template
              value_template: "{{ 'tamper' in searching }}"```
#

because when i change state of binary_sensor.doorbr01a both conditions become true and both scripts are called

#

ahh shit evrytime i post something i find the problem, its like posting it helps my brain reset

#

did a config check and its still loading the old code

#

Error loading /config/configuration.yaml: while parsing a block collection
in "/config/automations/Windows Automation Script Call Petro.yaml", line 1, column 3
expected <block end>, but found '?'
in "/config/automations/Windows Automation Script Call Petro.yaml", line 34, column 3

#

can you spot the error in the above code?

terse grove
weak fossil
#

correct

terse grove
#

ok, then

weak fossil
#

but its also in the object id

#

both aproaches should work, right?

#

searching = object _id

terse grove
#

sensor.sensor == 'tamper'

weak fossil
#

problem is that woiuld not work

#

because it can be atamper, btamper, or ctamper

terse grove
#

sensor.sensor.endswith('tamper')

weak fossil
#

and for the fiorst condition to avoid it being true if it ends with tamper

#

?

#

but still there must be a typo somewhere because i still get this error:

Error loading /config/configuration.yaml: expected '<document start>', but found '<scalar>'
in "/config/automations/Windows Automation Script Call Petro.yaml", line 63, column 1

terse grove
#

not sensor.sensor.endswith('tamper')

#

you could also use if then else instead

weak fossil
terse grove
#

🤷‍♂️

#

that should also work but you'

#

're saying it doesn't

weak fossil
#

no, the prob is i runned the config checker and its giving me errors

#

that is why the automation was still running the old code

#

i added you sugestions

#

but still Error loading /config/configuration.yaml: expected '<document start>', but found '<scalar>'
in "/config/automations/Windows Automation Script Call Petro.yaml", line 67, column 1

terse grove
#

did you copy from your paste again without using raw?

weak fossil
#

now this was writen by hand

#

how do you see those rare caracters?

terse grove
#

your missing a comment indicator on line 67

#

#----

#

instead of

weak fossil
#

argg fuck men LOL

#

i didnt see that haha

#

ok

#

yes now it works

#

but i still get getting all thse warnings in the logs (the only reasdon i reached out in the first place) https://dpaste.org/xV0Qp

#

🤦

#

i guess i will have to look in to your sugestion of moving away from state changes

terse grove
#

those warnings will happen based on how you have that automation set up

weak fossil
#

but im filtering them in the automation as per your sugestion, its the first condtion before any action

#
    condition:
      - condition: template
        value_template: >
          {{ new_state not in ['unavailable', 'unknown'] 
             and old_state not in ['unavailable', 'unknown'] 
             and new_state.state is not none 
             and old_state.state is not none }}
#

this is exactly what you told me to write when i first reached ot to get rid of the warnings

#

I mean, if i can have a condition that filters out everything causing the warnings right at the begining in the automation that will be calling the scripts, the automation should should fail here and the scripts should not be called and there should not be any more warnings, right?

terse grove
#

that's why I didn't have the original new_state and old_state getting grabbed prior to the condition.

weak fossil
#

I see, makes sense

weak fossil
#

Petro? how do i convert this line to my local timezone "{{ log_message.format(now().strftime('%A %d %B %Y at %X %p')) }}"

#

we are UTC +4

terse grove
#

If it's not local that means you don't have a timezone set on your system

#

if you have a timezone that's set on your system but you want it in a different timezone, you're SOL

weak fossil
#

the timezone showing in HAOS is my right time

#

my HA logs and everything else shows the right time

terse grove
#

then now() should show the right time

#

if now isn't showing correctly, you didn't set something properly when installing the software or your tz is not set properly on your system. Or you're not realizing the the message is correct.

#
{{ now() }}
{{ now().strftime('%A %d %B %Y at %X %p') }}
weak fossil
#

template editor will not even render {{ now() }}

#

ValueError: Template error: as_timestamp got invalid input 'None' when rendering template '{{ now() }}

terse grove
#

if those don't agree, you have a problem. If they agree and you have no tz, then your system is configured wrong. If they agree and have a TZ, then you're not realizing the time is correct.

weak fossil
#

had to delete everything in the editor

#

its outputing 4hrs behind

#

UTC time

terse grove
#

then you didn't set the timezone correctly in HA

#

or you screwed up the install on a virtual machine

weak fossil
#

ill have a look

#

is a HAOS install on a rpi

terse grove
#

then the timezone isn't set

#

can't really do much other than not setting the timezone in settings -> general

weak fossil
#

ok

#

you are right it was set to the default

#

😅 👍

#

dont know why all other times, logs etc.. matched my timezone 🤷‍♂️

weak fossil
#

ahh i see

weak fossil
#

@ petro, slowly getting there 🥰 I allready managed to convert a bunch of automations that used the same regex inputs and got them all working converted in to scripts triggered by your example automation

#

im trying to converta nother one that needs diferent inputs

#

im writting this to trigger the script i will write

#

but had to modify the regex

#

getting this error:

Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected '=') for dictionary value @ data['variables']['regex_sensor']. Got None. (See ?, line ?).

#

I think its the mods i did to the regex

#

would you mind having a look at that portion, i recall you mentioning something about a bug and having to add the + sign for it to work

weak fossil
#

this portion:

#
      searching: "{{ trigger.event.data.new_state.object_id }}"
      regex_result: "{{ searching | regex_findall('(room|living|kitchen)([a-z]+)([0-9]{2})') }}"
      regex_sensor: >
        {% set g, r, = regex_result | first | default(['', '']) %}
        {{ {'group': g, 'room_number': r} }}
terse grove
weak fossil
#

it works in the template editor

#

but still my automation shows doesnt pass the config check

#

🤦

#

Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected '=') for dictionary value @ data['variables']['regex_sensor']. Got None. (See ?, line ?).

terse grove
#

how many commas do you think belong here?

#
        {% set g, r, = regex_result | first | default(['', '']) %}
weak fossil
#

gotcha

#

sorry for bothering you so much, im trying to figure most of it out myself

#

its working now

#

i find it hard to spot these small errors

#

managed to convert the "easier" of my old automations, starting to work on the harder one

#

but yeah getting there slowly

weak fossil
#

@terse grove I have another problem i cant understant

#

I got the regex right, meaning in the template editor it outputs what i need

terse grove
weak fossil
#

its firing when i change the state of a group which is what i want

#

thjat is how i got the traces

#

i also added this line and trigger.event.data.new_state.domain == 'group'

#

so it only becomes true if its a group domain firing the automation

weak fossil
#

let me see

#

this is what you mean

#

but still the regex output is not populating

#

i also see im missing some groups in the entity id list it outputs, there is also group.living02 and group.kitchen01 and group.kitchen02 which are not listed in that trace 🤔

terse grove
weak fossil
#

ok i see got it

#

ill slowly get it

#

😅

#

cool thanks, i have a few other questions but let me write the automation and see how far i can get my myself 👍

weak fossil
#

its working but there is 2 small bugs i cant figure out, i commented everything should be easy for you to read

#

1 is the AC message (commented)

#

2 is the condition after the delay

            - condition: template
              value_template: >
                {{ run_off and away }}```
#

if i trigger the group_not_home and then back home (meaning away becomes false) its still runs the automation and passes this condition

#

if group becomes not_home and is back home when the delay as elapsed it should fail and not switch the ac OFF

#

im assuming i need to refresh the away variable in the running script somehow before it reaches this condition

#

Ahh there is one more thing i dont know how to do, (at least elegantly) 😅

#

when i call service: notify.BedroomPresenceAutomationsLogfile

I have 3 log files:

BedroomPresenceAutomationsLogfile
LivingPresenceAutomationsLogfile
KitchenPresenceAutomationsLogfile

#

idealy it should write to the right file based on what the trigger was group.room, group.living or group. kitchen

weak fossil
terse grove
#

hint: `{{ xomething here }}PresenceAutomationsLogfile"

weak fossil
#

i think i got this one figured out also, hang on let me post the code of what i did

#
  notification: >
    {% if regex_sensor.group == ('room') %}
      notify.BedroomPresenceAutomationsLogfile
    {% elif regex_sensor.group == ('living') %}
      notify.LivingPresenceAutomationsLogfile
    {% elif regex_sensor.group == ('kitchen') %} %}
      notify.KitchenPresenceAutomationsLogfile
    {% endif %}
#

and used notification in the service call

terse grove
#

orrrrrrrrrrrrrrrrrrrrrrrrrrr

#

{{ regex_sensor.group.title() }}PresenceAutomationsLogfile

weak fossil
terse grove
#

and make your group name for bedroom be bedroom instead of room

#

but you can do it the long template way

#

this goes back to the whole naming consistency thing that I mentioned awhile back

weak fossil
#

what does title() stand for

terse grove
#

it makes the word a title

#

not a title

#

A Title

#

petro vs Petro

#

hello world vs Hello World

weak fossil
#

basicaly capitalize?

terse grove
#

No

#

.capitalize only does the first letter

#

.title first letter of every word

weak fossil
#

I see, cool

terse grove
#

.upper all letters uppercase

#

.lower all letters lowercase

weak fossil
#

so it would be writen lower() for instance if i wanted to use that

#

?

terse grove
#

well, it's already lowercase if it's coming from an entity_id

#

which it is

weak fossil
#

well yeah but i mean that is the right way to write your examples, right?

terse grove
#

Not sure what you mean

weak fossil
#

no worries, i think i get it

#

seems everything is working except the delay check

weak fossil
#

when i try your aproach it fails the config check:

- service: {{ regex_sensor.group.title() }}PresenceAutomationsLogfile```
#

Error loading /config/configuration.yaml: while parsing a block mapping
in "/config/scripts/ac_automation_script.yaml", line 132, column 15
expected <block end>, but found '<scalar>'
in "/config/scripts/ac_automation_script.yaml", line 132, column 48

#
- service: notify.{{ regex_sensor.group.title() }}PresenceAutomationsLogfile```
#

The automation "AC Automation Script Call" (automation.ac_automation_script_call) has an action that calls an unknown service: notify.roompresenceautomationslogfile.

#

but no worries i think i will figure all this out

#

its just the delay thing that i have no clue how to aproach

weak fossil
#

its the last pc i need to figure out, i have allready converted all my state_changed trigger automations and all are working except for this little pc

weak fossil
#

I think i got it 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉

#

buahh its been a loong month 😩

#

Might still will bother you with a few small questions as i think im still reusing to much code and i know it can be done better 😅

But at least all my old automations are all ported and working 🥰