Automation not working with time as condition

I have a sunset automation with lux sensor instead of sun, this has worked all the time but has stopped working when I add time as condition. Why is that? I think it happened during my last update of hassio…

here is my automation that currentli does not work, if I remove time as condition it starts working. I dont want this automation to trigger in the middle of the day though

- id: '1509799694883'
  alias: LUX Sunset - Lampor PÅ
  trigger:
  - below: '400'
    entity_id: sensor.aeotec_zw100_multisensor_6_luminance_2
    platform: numeric_state
  condition:
  - after: '14:00:00'
    before: '23:00:00'
    condition: time
  action:
  - data:
      entity_id: switch.lampor_eldstad
    service: switch.turn_on

If you are going to add other conditions later:

  condition:
  - condition: time
    after: '14:00:00'
    before: '23:00:00'

Or if this is the only condition you will ever need:

  condition:
    condition: time
    after: '14:00:00'
    before: '23:00:00'

so you are saying that my automation was correct and should work?

I’m using the webgui to make my automations, and noticed that the condition: time is placed after the actual conditions. I wonder why it does that, I changed the code so that condition: time now is before “after:…”

The ldash “-” used for a list item looked to be in the wrong place.

That would explain it.

what do you mean when you say it’s not working? it doesn’t run at all, it doesn’t run when desired, there are errors in the log, etc?

it looks like it should be ok format-wise.

It didn’t run at all, but as soon as I swapped places of the code so it looks like below it started to work!

  condition:
  - condition: time
    after: '14:00:00'
    before: '23:00:00'

The weird thing is that all was done in the webgui though. I have seen this in many of my auomations so it’s some kind of a bug? at least now I know, thanks!

I didn’t think that would matter but apparently it does. unless you had some other problem in whitespacing that was fixed when you moved stuff around.

But that’s why I don’t use the automation editor. I don’t like the readability of the resulting code.

This is so strange because in my case neither the first nor second version does work…
The code is pretty easy and does work perfectly when no condition is applied.

- id: '1578087565182'
  alias: termoNIL ON (23:00-7:00)
  description: ''
  trigger:
  - platform: template
    value_template: '{{ states(''input_number.mintemp_nil'')|float > states(''sensor.sonoff_th16_01_am2301_temperature'')|float}}'
  condition:
  - condition: time
    after: '23:00:00'
    before: '07:00:00'
  action:
  - data: {}
    entity_id: switch.sonoff_th16_01
    service: switch.turn_on

It does basically turn on an electric heater at night in case the temp goes below a certain threshold (input_number.mintemp_nil).

I’m sure that that the solution is easy to spot but really tried anything to make it work using the time condition (I’ve also tried to split the timeframe 23:00 - 23:59 and 00:00 - 7:00 with no success).

Thanks fellas…

It can’t ever be after 11pm and before 7am on the same day.

Thanks a lot tom_l.
I would you fix it?
The day is not specified, it should only consider the condition when the trigger is enabled… Regardless the day… I guess…
I will try, anyway, to set the condition from 00:00 and 07:00 and see what happens but would really like to know the best way to manage these kind of situations for future applications.

Cheers

It should work, it’s even an example in the documentation.

It looks like your template is apostrophes and not quotes.

  - platform: template
    value_template: '{{ states(''input_number.mintemp_nil'')|float > states(''sensor.sonoff_th16_01_am2301_temperature'')|float}}'

shoudl be

  - platform: template
    value_template: '{{ states("input_number.mintemp_nil")|float > states("sensor.sonoff_th16_01_am2301_temperature")|float}}'

popboxgun,
the problem is not the trigger but the condition instead…
The automation does work untill I try to impose the working timeframe (23:00-07:00).
I will try anyway to change the code and see the outcome during next days (I have a quite busy week).

Thanks for your help

condition:
  condition: or
  conditions:
    - condition: time
      after: '23:00:00'
    - condition: time
      before: '07:00:00'
1 Like

Neither…
It just turned on at 7:56 with no reason…


I really cannot understand the reason why.

Thanks anyway for your help guys.
Cheers

*EDIT
This is the current version code:

- id: '1578087565182'
  alias: termoNIL ON (23:00-7:00)
  description: ''
  trigger:
  - platform: template
    value_template: '{{ states(''input_number.mintemp_nil'')|float > states(''sensor.sonoff_th16_01_am2301_temperature'')|float}}'
  condition:
    condition: or
    conditions:
    - condition: time
      after: '23:00:00'
    - condition: time
      before: 07:00:00
  action:
  - data: {}
    entity_id: switch.sonoff_th16_01
    service: switch.turn_on

The 7:00 isn’t quoted

Oh crap…
You see? The details man, the details…
I’m not good in coding, I’ve always said that.

Cheers mate, sorry for the silly mistake (will report the outcome on next days)

It’s always obvious when someone looks with fresh eyes…

it’s also not what was originally posted.

In fact, it was the original code implemented with suggestions.
Apparently the automation is working fine even if, in the history, I’ve found an “on” condition after 7AM… Maybe my wife? One of my daughters? Wrong code?
I will keep investigating fellas but apparently you have solved my problem.
Cheers

No way, the automation keeps being triggered after 7AM (when someone opens the window to change the air in the room). The switch has been manually turned off.
Capture01


I really cannot explain myself the reason why…