Is there a way to create an automation that turns OFF another automation for a certain time (and then ON again) ?
yes.
the services are âautomation.turn_offâ & âautomation.turn_onâ and are called just like any other service in the first automations actions.
Thanks for your valuable help !!!
YEs you can do this. But I would say a more proper way is to have an input_helper that controls whether an automation runs or not and toggle that rather than actually enabling/disabling automations. It is more pragmatic.
Instead of one automation controlling anotherâs schedule, put the schedule directly into the automationâs condition (or even into its Template Trigger if it uses one).
Something that totally puzzles me is when I have a condition of Time at 5 pm the condition tests ok but when I set the condition at 6 pm or later it tests as not ok.
Trigger : entity X
Condition : Fixed Time after 7 pm before 12 am
Instead of posting pseudo-code, post the automation in YAML format.
I agree with you that seems more logical, but I donât get it to work.
What I am trying to do is with an entity of the Jewish Calendar integration that is named âMelacha in effectâ. This entity is either ON or OFF depending on specific day/time in the Jewish Calendar.
I think that I get it to work for ON by just adding the entity as Trigger, but I donât know (and have tried several options) how to set it so that a specific Action only runs when the entity if OFF.
I donât understand your reply. You originally posted this:
To help you, we need to see what you actually created that, when tested, didnât work for you. Because this doesnât represent anything we can examine to determine why it failed:
Trigger : entity X
Condition : Fixed Time after 7 pm before 12 am
Post the automation you created, in YAML mode, so we can examine it.
I donât how copy/paste exactly like it shows in YAML mode, I did a copy/paste to MS Word and then here.
Thanks for trying to help me. I am novice at Home Assistant
Trigger
platform: time
at: â14:55:00â
Condition
condition: state
entity_id: binary_sensor.jewish_calendar_issur_melacha_in_effect
state: âoffâ
Action :
service: media_player.play_media
data:
media_content_type: audio/mp3
media_content_id: http://s22.myradiostream.com:7728/listen.mp3
target:
entity_id: media_player.mazal
- In the upper right corner of the Automation Editor is an icon with three vertical dots.
- Click it and it will reveal a menu.
- Select âEdit in YAMLâ
- The Automation Editor will switch from Visual Mode to YAML mode.
- Select all of the displayed YAML code using your mouse then right-click and select Copy. If you are using a phone or tablet, the select-copy procedure is different (let me know if you need help with that).
- Return to your forum message and paste the YAML code.
- Select the YAML code you just pasted and then click the </> icon in the forumâs editor to format it properly.
[alias: M1. Music - Sky Radio - 5:55 am
description: ''
trigger:
- platform: time
at: '05:55:00'
condition:
- condition: state
entity_id: binary_sensor.jewish_calendar_issur_melacha_in_effect
state: 'off'
action:
- service: media_player.play_media
data:
media_content_id: >-
http://playerservices.streamtheworld.com/api/
livestream-redirect/SKYRADIOAAC.aac
media_content_type: audio/aac
target:
entity_id: media_player.mazal
mode: single
Thanks again for guiding me. I really appreciate
This is what I am trying to do.
If time is 7:55 pm and the entity is OFF, the action runs.
If the entity is ON then the action does not run
[alias: M1. Music - Sky Radio - 7:55 pm test
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.jewish_calendar_issur_melacha_in_effect
to: 'off'
condition:
- condition: time
before: '00:00:00'
after: '19:55:00'
action:
- service: media_player.play_media
data:
media_content_id: >-
http://playerservices.streamtheworld.com/api/
livestream-redirect/SKYRADIOAAC.aac
media_content_type: audio/aac
target:
entity_id: media_player.mazal
mode: single](https://)
In the above code, triggering on the binary sensor will only happen exactly when the the state changes to off, then it will check the condition (between 19:55 and 00:00), so if the sensor changes to off outside of that time span times, the automation will never proceed to the action.
But, from your description, I understand you only ever want it to (possibly) trigger at one specific time, so the time platform is the correct thing to trigger on, then you check the condition of the binary sensor â if it is âoffâ it will proceed to the action.
So this looks correct to me:
alias: M1. Music - Sky Radio - 7:55 pm test
description: ''
trigger:
- platform: time
at: '19:55:00'
condition:
- condition: state
entity_id: binary_sensor.jewish_calendar_issur_melacha_in_effect
state: 'off'
action:
- service: media_player.play_media
data:
media_content_id: >-
http://playerservices.streamtheworld.com/api/
livestream-redirect/SKYRADIOAAC.aac
media_content_type: audio/aac
target:
entity_id: media_player.mazal
mode: single
Thanks !!!
I think that I understand your âTimeâ explanation but am not sure.
If the state is already off before 19:55 (for argument sake it changed to off 2 hours or a day earlier) and there is no state change between 19:55 and 0:00, will the action still run at 19:55 ?
If not, how can I set the automation that it runs action A (radio station A) at 19:55 if the entity is off and run action B (radio station B) at 19:55 if the entity is on ? I assume 2 separate automations ?
Thanks again !!!
No, in your original example it would not run at 19:55.
When you are selecting triggers, remember that a trigger is something that happens or changes. For many automations, the right trigger to use is one that is linked to an event that is closest to the action in real time. As an example, letâs say you want lights to come on when you are moving around the house at night. Your trigger should be that motion is detected. Then you could add the condition that it is after sunset.
You can use two automations, or modify the condition and action portions of the automation that @gonzotek provided⌠using an If/Then or Choose action. Since you are working with a binary output (Radio A or Radio B), the If/Then action will work fine.
alias: M1. Music - Sky Radio - 7:55 pm test
description: ''
trigger:
- platform: time
at: '19:55:00'
condition: []
action:
- if:
- condition: state
entity_id: binary_sensor.jewish_calendar_issur_melacha_in_effect
state: 'off'
then:
- service: media_player.play_media
data:
media_content_id: >-
http://playerservices.streamtheworld.com/api/
livestream-redirect/SKYRADIOAAC.aac
media_content_type: audio/aac
target:
entity_id: media_player.mazal
else:
- service: media_player.play_media
data:
media_content_id: >-
##radio station B##
media_content_type: audio/aac
target:
entity_id: media_player.mazal
mode: single
Drew, Thanks⌠I have learned so much about HA the past couple of days and I still have to learn a lot more.
Your IF-THEN-ELSE is a real discovery for me and is very similar to what I use with ISY=Polisy of UDI.
Thanks again