Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


peejayw

1748 posts

Uber Geek


#311760 12-Feb-2024 14:00
Send private message quote this post

How would I go about producing an automation that will turn on a switch every second day at a set time? Thanks.





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


Create new topic
amanzi
Amanzi
1166 posts

Uber Geek

ID Verified
Trusted
Lifetime subscriber

  #3194331 12-Feb-2024 14:09
Send private message quote this post

Editing this post to remove the faulty AI-generated code...

 

This automation should work - although it will still need to be tested.

 

alias: Turn on switch every second day at 8 PM

 

description: ""

 

trigger:

 

- platform: time

 

at: "20:00:00"

 

condition:

 

- condition: template

 

value_template: "{{ now().day % 2 == 0 }}"

 

action:

 

- service: switch.turn_on

 

target:

 

entity_id: switch.your_switch_entity_id

 

data: {}

 

mode: single

 

 


 
 
 

Backblaze Unlimited Backup. World’s easiest cloud backup. Get peace of mind knowing your files are backed up securely in the cloud (affiliate link).
peejayw

1748 posts

Uber Geek


  #3194332 12-Feb-2024 14:16
Send private message quote this post

Thats impressive, AI at work. Will try and let you know. Thanks.





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


amanzi
Amanzi
1166 posts

Uber Geek

ID Verified
Trusted
Lifetime subscriber

  #3194334 12-Feb-2024 14:21
Send private message quote this post

The only downside to this approach is that it will only match dates that are divisible by 2, e.g. 2nd, 4th, 6th, 8th, etc. If you wanted it to trigger on odd days instead, then you'd need to use a template condition type with: {{ (now().day % 2) == 1 }}




peejayw

1748 posts

Uber Geek


  #3194354 12-Feb-2024 14:48
Send private message quote this post

I tried that suggestion, got the following error message......

 

 

 

Message malformed: extra keys not allowed @ data['days']





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


amanzi
Amanzi
1166 posts

Uber Geek

ID Verified
Trusted
Lifetime subscriber

  #3194360 12-Feb-2024 15:13
Send private message quote this post

Ah - interesting. Looks like the time-pattern doesn't support "days". The Google AI is not that impressive :-)

 

Try use the "template" conditional instead:

 

alias: Turn on switch every second day at 8 PM

 

description: ""

 

trigger:

 

- platform: time

 

at: "20:00:00"

 

condition:

 

- condition: template

 

value_template: "{{ now().day % 2 == 0 }}"

 

action:

 

- service: switch.turn_on

 

target:

 

entity_id: switch.your_switch_entity_id

 

data: {}

 

mode: single

 

 

 


peejayw

1748 posts

Uber Geek


  #3194372 12-Feb-2024 15:50
Send private message quote this post

Thanks, tried that with the same error message as before.





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


amanzi
Amanzi
1166 posts

Uber Geek

ID Verified
Trusted
Lifetime subscriber

  #3194377 12-Feb-2024 16:09
Send private message quote this post

That might be an issue on your side. I tried the above code in my Home Assistant and it loaded up fine. Should look something like this:

 




SpookyAwol
612 posts

Ultimate Geek


  #3194379 12-Feb-2024 16:17
Send private message quote this post

Instead of messing around with days, you could just use a boolean helper.

Day 1, If boolean off, set boolean to true, turn on lights.

 

Day 2, if boolean true, turn off


peejayw

1748 posts

Uber Geek


  #3194380 12-Feb-2024 16:18
Send private message quote this post

OK, so instead of entering as yaml I used the visual editor and copied from your screenshot and that was accepted without errors.

 

So all going well it should not trip tomorrow and turn on Wednesday, will advise.

 

Thanks so much for your help.





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


eluSiveNZ
175 posts

Master Geek


  #3194384 12-Feb-2024 16:29
Send private message quote this post

Would it be easier to create a calendar event (within the Home Assistant calendar) set to repeat every second day, and use that as the trigger in the automation?


peejayw

1748 posts

Uber Geek


  #3194385 12-Feb-2024 16:33
Send private message quote this post

SpookyAwol:

 

Instead of messing around with days, you could just use a boolean helper.

 

 

I need to brush up on my booleans 😬





 I'm supposed to respect my elders, but it's getting harder and harder for me to find one now.


pih

pih
572 posts

Ultimate Geek

Lifetime subscriber

  #3194389 12-Feb-2024 16:52
Send private message quote this post

Down side of the suggested response is that on months with odd numbers of days (29/31) you'll get the automation triggering either twice in a row (triggering on odd days) or not triggering for 2 days (of triggering on even days). The boolean toggle might work better but won't remember your "schedule" if it's disabled/skipped for a day. If you really want to make sure it sticks to a fixed day-on-day-off schedule, do it based on epoch instead. Something like this (also AI generated, untested):


value_template: "{{ (now() - as_datetime('19700101T00Z')).days % 2 == 0 }}"


neb

neb
9057 posts

Uber Geek

Trusted
Lifetime subscriber

  #3194410 12-Feb-2024 18:27
Send private message quote this post

Sort of a meta-question but it does apply to the above, does anyone know why HA tries to use a markup language as a scripting language? If I was going to script something for automation, YAML is pretty much the last tool I'd reach for, every single thing you want to do with HA becomes an awkwardly painful exercise in lateral thinking as you try and guess how you'd express something like a control loop using a mechanism that can't do that but can only do markup.

amanzi
Amanzi
1166 posts

Uber Geek

ID Verified
Trusted
Lifetime subscriber

  #3194412 12-Feb-2024 18:36
Send private message quote this post

neb: Sort of a meta-question but it does apply to the above, does anyone know why HA tries to use a markup language as a scripting language? If I was going to script something for automation, YAML is pretty much the last tool I'd reach for, every single thing you want to do with HA becomes an awkwardly painful exercise in lateral thinking as you try and guess how you'd express something like a control loop using a mechanism that can't do that but can only do markup.

 

I'm not a fan of YAML at all, but all this is doing is describing the automation in an "if this then that" type of manner. So the YAML markup is not actually doing any scripting, although you can include template blocks which are based on Jinja which means you can include Python-like code in the YAML files.


Handle9
9928 posts

Uber Geek

Trusted
Lifetime subscriber

  #3194467 13-Feb-2024 07:34
Send private message quote this post

SpookyAwol:

 

Instead of messing around with days, you could just use a boolean helper.

Day 1, If boolean off, set boolean to true, turn on lights.

 

Day 2, if boolean true, turn off

 

 

That's how I'd do it. Toggle the boolean on a schedule then follow with an if statement


Create new topic





News and reviews »

Synology Introduces BeeStation
Posted 23-Feb-2024 14:14


New One UI 6.1 Update Brings Galaxy AI to More Galaxy Devices
Posted 23-Feb-2024 10:50


Amazon Echo Hub Available in New Zealand
Posted 23-Feb-2024 10:40


InternetNZ Releases Internet Insights 2023
Posted 20-Feb-2024 10:31


Seagate Adds 24TB IronWolf Pro Hard Drives for Multi-user Commercial and Enterprise RAID Storage Solutions
Posted 19-Feb-2024 16:54


Seagate Skyhawk AI 24TB Elevates Edge Security Capacity and Performance
Posted 9-Feb-2024 17:18


GoPro Releases Quik Desktop App for macOS and Introduces Premium+ Subscription Tier
Posted 9-Feb-2024 17:14


Ring Introduces New Ring Battery Video Doorbell Pro
Posted 9-Feb-2024 16:51


Galaxy AI Transforms the new Galaxy S24 Series
Posted 18-Jan-2024 07:00


D-Link launches AI-Powered Aquila Pro M30 Wi-Fi 6 Mesh Systems
Posted 17-Jan-2024 20:02


Newest LG 4K Lifestyle Projector Doubles as Art Objet
Posted 9-Jan-2024 15:50


More LG Smart TV Owners Set To Enjoy the Latest webOS Upgrade
Posted 9-Jan-2024 15:45


Panasonic Announces the Z95A and Z93A With Fire TV Built In
Posted 9-Jan-2024 15:30


Amazon Echo Pop Review
Posted 8-Jan-2024 14:22


Samsung Tab S9 FE Review
Posted 17-Dec-2023 08:26









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.







Backblaze unlimited backup