#The Bates Motel
1 messages · Page 1 of 1 (latest)
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
The delay condition needs to move before the condition. If it needs to execute before the check.
Back where I it originally was
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)
It won’t if nothing has been on over the duration
I don’t know how else to explain that to you
ok gotcha
It’s counting all sensors that are on for the specified duration. If they aren’t on, it won’t trigger.
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
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
i dont think i ever checked again for that
It didn’t make sense to me why you were doing that
i just made sure they where still open
Post your old code, I’ll point out the line.
soory wrong link
i have several following the same format
im gonna nedd to port your example over im in for a ride 😭
224 to 231 check the last changed vs the duration
Specifically 227 and 230 that do the calc
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
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
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
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
but yes you are right if i had to code everything today it would be very different
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
moved the delay as the fist thing after the action: https://dpaste.org/6Ggk8
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 ?).
here is the thread tinkered created for me when i reached out foir help: https://discord.com/channels/330944238910963714/1015316542164054047
(to hire someone) rest of conversation is in the general chat
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
you had to move the entire choose
# 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
ok, let me se if i can explain exaclty want i wanted to achieve and what my code did perfectly before:
-
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
Ok, so why are you checking all that crap in the choose then?
because its the best i knew how to do back in the day and also from your guys advice
ok
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
🙏
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?
Error loading /config/configuration.yaml: mapping values are not allowed here
in "/config/automations/Windows Automation Template Petro.yaml", line 4, column 16
should have taken this as the tamplate to work on https://dpaste.org/ADAaJ
it has all the corrections and my comment to follow along 😅
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
same result
this worked fairly well
there's no way, it passes yaml validation
copy/paste the whole thing
don't try to piece meal it in to what you have
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
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
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 ?).
ah ok, that might be a bug
change away to
away: >
{{ state(group) in ['off', 'not_home'] }}
🤷♂️
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
I fixed the timer stuff
you actually broke it
when you added your input_datetime stuff
ii managed all the traces to make sense on my coide and all was looking out good
yes but you hard coded it to the bedroom
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*
like what?
just found some more bugs
I've been coding for years, it's just second nature
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
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
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
ok, i think my monitor is from 2010
ny
ok your autoimation as is its not trigerring
didn't change the trigger
post the changed variables in the trace
i added magic, need to see if it's working
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
you wanna screen share?
giver me a secd headphones
hangout
a8jcv6z3
keep message
@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
Just post it in here
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
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
@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)
Can you post the script again? I don’t have it anymore
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
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
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
but the delay is based on the triggering entity, which is a window or a door. and that can lead to unexpected results
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
Try this
then post the Changed Variables for the newly added variables step that further down in the script.
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
same thing
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
no i dont, i replaced it completely
then you should have errors in the logs or it should be updating in the scirpt window
just copied my old code to a new tab in notepad and replaced the content of the working file with your code
and you saved the file after pasting?
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
ok, and you're reloading scripts, correct?
like 10 times allready
ok, then you should have errors in the logs or there should be new traces after you trigger it
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
whatever it is, it's the stupid invisible characters again
did you copy raw or did you copy without doing the raw?
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```
is that it?
still fails
that is the door i openend
ah, forgot about the eq on
there are 2 doors and 2 windows
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.
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
and now you have all the information you need to debug things
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```
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
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!
np
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
you can add a condition to not turn it off if it's already off
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!
You actually allready had the condition in place and i didnt even realize (the run_off variable) problem is im testing without the phisical devices so although the script runs it cant turn off the AC until its plugged in 😅
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
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 😅
this is the script, its pretty simple, but as i mentioned it calls for bedroom as location https://dpaste.org/uFEq3
duplicate that code and make a new var
something_else:
br: foofoo
lr: barbar
kitchen: kkadjfklashdf
some_other_location: "{{ something_else.get(sensor.room, 'unknown') }}"
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
No, I doubt they ever will. That's what helper entities are supposed to be.
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)
They are pretty limitless at this point, you just have to declare them before using them
anyway, let me continuing trying to replicate your code
isnt this valid? https://dpaste.org/NpJWc
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
@terse grove
Pretty much following your guidelines I managed to convert this : https://dpaste.org/3UtSb#L1,3
In to this: https://dpaste.org/XFHeB
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 😅
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 🙏
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
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'}
I think i got i petro!
automation: https://dpaste.org/2tRSP
and this is my script: https://dpaste.org/oLytE
found it hard to figure the regex out and everything else but it seems to work
this was my old file https://dpaste.org/3UtSb#L1,3
so just to let you know the time you spent helping me is being put to good use 🥰
but struggling with some things still
Sorry, was at work all day
that regex should work
just reachiung out to you because you kind of know what im trying to do and can point out faults easy
yes it works 🙂
Nice, the script is short too
just keep using that pattern and you should be good for all your crazy automations
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
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
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
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.
what does separated the identifiers out with _, mean?
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
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
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
what about this
that's an even bigger change
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?
there is, but it requires you to create dynamic groups and then fire off entities in the groups
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?
Can you elaborate on this? is it like fes is propossing or a different aproach, and what would be best ?
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
@terse grove can you check this out?
i have 2 automations calling 2 scripts:
https://dpaste.org/6V959
https://dpaste.org/E7Mxw
this works fine
tried to combine both calls in the same automation and my system freezes completely:
https://dpaste.org/VJqAn
can you think of a reason this would happen or am i doing something wrong?
looks correct
Do you have all these automations running or did you turn off the other ones?
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 🤷
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
that's why thefes suggested moving away from state_changed events
you can try that but your system may still freeze
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
yes i guess its a better solution but that is opening a completely new caa of worms 😅
@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?
you should be using sensor.sensor, regex will be putting tamper in that field if I remember correctly
correct
ok, then
but its also in the object id
both aproaches should work, right?
searching = object _id
sensor.sensor == 'tamper'
sensor.sensor.endswith('tamper')
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
ok, but regardless is this not right?
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
did you copy from your paste again without using raw?
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
those warnings will happen based on how you have that automation set up
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?
No you aren't variables execute first, that's where the errors are coming from
that's why I didn't have the original new_state and old_state getting grabbed prior to the condition.
I see, makes sense
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
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
the timezone showing in HAOS is my right time
my HA logs and everything else shows the right time
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') }}
template editor will not even render {{ now() }}
ValueError: Template error: as_timestamp got invalid input 'None' when rendering template '{{ now() }}
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.
then you didn't set the timezone correctly in HA
or you screwed up the install on a virtual machine
then the timezone isn't set
can't really do much other than not setting the timezone in settings -> general
ok
you are right it was set to the default
😅 👍
dont know why all other times, logs etc.. matched my timezone 🤷♂️
based on your browser
ahh i see
@ 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
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} }}
regex_result: "{{ searching | regex_findall('(room|living|kitchen)([0-9]{2})') }}"
hey petro yes i got that figured out
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 ?).
how many commas do you think belong here?
{% set g, r, = regex_result | first | default(['', '']) %}
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
@terse grove I have another problem i cant understant
I got the regex right, meaning in the template editor it outputs what i need
this is the automation: https://dpaste.org/8OCTM
but if i follow its traces its not outputing the variables from the regex: https://dpaste.org/JcYVw#L37,43,46
Look at the entity it’s searching. It’s an automation so it shouldn’t fire.
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
ok now i undestand what you said
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 🤔
Look at the searching variable. It doesn’t match what you’re looking for. It’s not the entity you think it is
ok i see got it
my bad, it is working https://dpaste.org/Tf7Zc#L22
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 👍
@terse grove im going to bug you a little bit more:
I managed to convert this: https://dpaste.org/wH7hg
In to this:
Automation script call: https://dpaste.org/ozVo9
Script: https://dpaste.org/o1NT2
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
found the typo in this allready so dont worry about that
You just have to temlapte the first word that should come from the triggering regex
hint: `{{ xomething here }}PresenceAutomationsLogfile"
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
orrrrrrrrrrrrrrrrrrrrrrrrrrr
{{ regex_sensor.group.title() }}PresenceAutomationsLogfile
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
what does title() stand for
it makes the word a title
not a title
A Title
petro vs Petro
hello world vs Hello World
basicaly capitalize?
I see, cool
well yeah but i mean that is the right way to write your examples, right?
Not sure what you mean
this
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
this
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