Condition fails

I have a automation that has a condition to check if script is not running and is after 4am and before sunrise. For some reason the script will not run from automation but does if I manually start it. On the Overview page it shows “Execute” next to the script which I think might be why it is not working since it is not in an off state. I have not found any information in the documentation that mentions this “Execute” indicator. My condition is:
condition: and
- condition: state
entity_id: script.morning_motion
state: ‘off’
- condition: or
- condition: time
after: ‘03:40:00’
- condition: sun
before: sunrise

  • service: script.turn_on
    entity_id: script.morning_motion

Not formatted correctly. Which makes it very difficult for us to help you.

Please read point 11 here and edit your post: How to help us help you - or How to ask a good question

Tom, Not that it would make much difference, I am guessing as to what the automation edit is striving at.

John, the execute shows that the script has no timer action (otherwise it would have a binary toggle) and that you can just execute it, bypassing the triggers and conditions (though not conditions in the action:)
I would probably use a condition: template with “{{ is_state(‘script.sc_light_hall_timer’, ‘off’ ) }}”
But your formatting, as Tom says, makes it hard to read

Thanks for the reply. Sometimes I have difficulty finding things in the docs. I have stripped it down with no condition and found that the script is not being executed. I have tried using the automation editor yet it still will not fire. Here is my automation, help with getting this to work would be much appreciated.

- id: '1569630741558'
  alias: test
  - at: 09:32:00
    platform: time
  condition: []
  - data:
      entity_id: script.night_motion
    service: script.toggle

Also I have tried using service: script.turn_on but that also does not work.

And there’s the rub.
The automation editor is fairly new, I don’t know of anyone helping on the forum who uses it.
Calling anyone that does !
It produces some Wacky code we are still trying to get our heads round
Generally we use samba and our personal favourite editors, steering clear of the automation editor as it strips out any comments as well as inserting ‘extra’ stuff
Until we can purchase, install and configure a new HA instance each we aren’t going to be able to help much with this.
We could write you code that would work if cut and pasted in over samba and an editor or ssh’d in with nano or vim etc. But the editor does not seem to like such code so there may be conflicts
Look around the forum check what others have done, unfortunately you seem to be caught in a transition period.

Glad to see you got the formatting sorted, though from what we’ve just learned, that may not be the actual formatting in the actual file.
Do you have a favourite text editor ?
What platform is your computer?

I also use notepad++ and edit the files manually. Just wanted to see if the editor would provide some in site to where the problem is. I have been able to determine that the issue is how i call the script. If I use entity_id: script.1569530171754 it works, but if I use entity_id: script.night_motion it does not. If I use only notepad++ can i use some other name instead of the ID number that the editor uses?

Yes you can,
But I’ll just call in some fresh eyes on this as what you have tried should have worked.
tom_l, finity, pnbruckner - any of you aware of this behaviour?

As mentioned in the sticky post please don’t tag folks like that.

If you’re using the UI editor you’ll always get a numeric ID for the entity_id.

You can manually edit scripts.yaml and change the script name (see here) to whatever you want.

Sorry, its just that the 4 of us were discussing something similar on another thread, this seemed pertinent.

Tink raises a good point, did you name (give it an alias) your script ‘script.night_motion’ and if so how, or are you making an assumption?
Can you show your script ?
Where are they ? Do you have a script.yaml and automation.yaml file? Are they in there ? or your configuration.yaml ?

Also, your automation is triggered by what ?
The conditions check that your morning script is not running (how long does that take? What’s in that.?) then it’s either before sunrise OR after 03:40 (that equates to ‘any time’ doesn’t it.?)
And then run the script that you were checking wasn’t running ?

I was able edit the script file and change the ID to a friendly name and now can call it from the automation. The syntax of my script file is not exactly how it is described in the docs as referenced by Tinkerer.

As for the condition it is to accomplish the following:

  1. Check and see if the script is not running
  2. Check that the time is after 3:45am and before sunrise.

My trigger is just for testing but will be replaced with a motion sensor once I get the automation working correctly.

My automation is:

  alias: Motion in Morning
  - at: '07:17:00'
    platform: time
    condition: and
    - condition: state
      entity_id: script.morning_motion
      state: 'off'
    - condition: or
      - condition: time
        after: '03:45:00'
      - condition: sun
        before: sunrise
  - service: script.turn_on
    entity_id: script.morning_motion

My script is:

  alias: Morning Motion
  description: Turn on Fireplace and TV Light
  - service: switch.turn_on
      entity_id: switch.smart_switch_switch
  - delay: 00:00:15
  - service: switch.turn_on
      entity_id: switch.zooz_zen26_s2_on_off_wall_switch_switch

Looks like I am getting close.

You’ve missed the most important part of the script, what’s on the line above alias?

1 Like

I just noticed that in the previous post it removed the first line of the script. Instead of the ID that the editor put in, I replaced it with ‘night_motion’:. Note that the docs do not show the single quote, not sure if it is required.

Yeah, closer
Your alias needs to be ALL lower case and NO spaces
The system will try to correct/interpret but you may get odd results
Just go with: morning_motion
If you ever see “incorrect slug” or similar that’s what it’s referring to.
So using notepad++ : -
The script delay should be in quotes ‘00:00:15’
In your conditions : -
Remove the whole “condition: and” line
And the same for the “- condition: or” line and the “conditions:” line blow that
The unindent (take 2 spaces out from) the following lines so they look like the first condition, all nicely in line.
See where that gets you.

But why not put the delay and the switch turn on in the automation?
Also nothing stops you from turning on something that is already on so get rid of the script running, in doesn’t do anything.

Edit: though if you want to be clear, you could change the condition to check the switch was off. So it only ever runs to turn it on the switch the 1st time but may repeat in the 15 sec delay, again no problem.

No it’s not but a lot of people do it, not a problem

Good catch

Alias has no restrictions

Okay, I probably do it then, to be consistent in what I call stuff