Different timing on action day and night

Hi i’m switching a relay to control a pump that circulates water in my aquaponics system. I would like to do this at various frequencies depending on day and night and when i’ve got that sorted add temperature into the equation.
I have hassio installed in a docker on a virtual machine running on a base machine which is windows.
The system is running fine and various time base automations are running very reliably the last few months.
I have just being doing automations using the automation assistant but would like to write directly, i’m a bit confused with the id that is a long number that they all begin with? oif I write directly what do i put?

However the main question of this topic is to understand why one of the two automations pasted below works perfectly and the other for night does not work.
In my thinking the 1st triggers every 50 minutes and if its after sunrise and before sunset it turns on the pump for 14 minutes. This works.
The 2nd triggers every 2 hours and if its after sunset and before sunrise it turns on the pump for 15 minutes except it does not work!
Thanks
Keith

- id: '1585255113954'
  alias: GreenHouse Centre Bed MainPump
  description: '# 8'
  trigger:
  - minutes: /50
    platform: time_pattern
  condition:
  - after: sunrise
    before: sunset
    condition: sun
  action:
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_on
  - delay: 00:14:00
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_off
- id: '1588956061523'
  alias: CentreBed Night Pump
  description: ''
  trigger:
  - hours: /2
    platform: time_pattern
  condition:
  - after: sunset
    before: sunrise
    condition: sun
  action:
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_on
  - delay: 00:15:00
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_off

The id parameter is optional. It is only necessary if you want to be able to edit the automation in the UI. It can be anything, as long as it’s unique. I don’t use the automation editor in the UI at all, and none of my automations have an id.

Actually, it doesn’t. It triggers whenever the minutes component of the current time is a multiple of 50. That happens only once an hour at XX:50:XX.

That’s your problem. It can’t be after sunset and before sunrise at the same time. You need a condition that is true after sunset or before sunrise. The easiest way to do that is:

- condition: state
  entity_id: sun.sun
  state: below_horizon

That assumes you’ve enabled the sun.sun entity.

See more options documented here.

Thankyou phil.
How then do you trigger every 50 mins?
Why does the first work as its after and before?
My code now, says indentation problem?

- id: '1588956061523'
  alias: CentreBed Night Pump
  description: ''
  trigger:
  - hours: /2
    platform: time_pattern
  condition: state
  - entity_id: sun.sun
    state: below_horizon
  action:
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_on
  - delay: 00:15:00
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_off

Sorted the indentation problem.
Hyphen was in wrong place sorry.
still a bit confused about the time_pattern parameters.
Thanks.

Because it’s after sunrise and before sunset. It goes midnight, sunrise, sunset, midnight. Sunrise is always before sunset (because the way the sun condition works is it’s only considering sunrise & sunset of a given day, not sunset from one day and sunrise of the next day.)

The condition is wrong. Instead of this:

  condition: state
  - entity_id: sun.sun
    state: below_horizon

it should be this:

  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon

Thanks for your help.
just wondering why the below does not trigger anything.
also how do I get an automation to show up as an entity when coded?

- id: '1588956061523'
  alias: CentreBed Night Pump
  description: ''
  trigger:
  - hours: /2
    platform: time_pattern
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_on
  - delay: 00:15:00
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_off

You still haven’t entered the condition correctly (as I showed you.) That is why it’s not triggering, or even showing up as an entity. Did you not see any errors in the log or when you checked the config???

You are missing the condition: link. This is what your automation should be:

- id: '1588956061523'
  alias: CentreBed Night Pump
  description: ''
  trigger:
  - hours: /2
    platform: time_pattern
  condition: # <=========== You misssed this line
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_on
  - delay: 00:15:00
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_off

Thankyou for your patience, I will correct that, the condition being in twice confused me as i was pasting the new code in.
Hopefully will work now.

I still have no joy, maybe there are other issues.
It will be long but i’ll post the whole automation file and the log errors.
Thanks if you can help.

LOG
Invalid config for [automation]: required key not provided @ data[‘trigger’][1][‘platform’]. Got None. (See /config/configuration.yaml, line 13). Invalid config for [automation]: [entity_id] is an invalid option for [automation]. Check: automation->entity_id. (See /config/configuration.yaml, line 13).

20:37:45 – Hass.io (ERROR)

Unable to find referenced entities automation.centrebed_night

20:37:20 – helpers/service.py (WARNING)

Exception occurred:

20:28:29 – /usr/local/lib/python3.7/site-packages/zeroconf/init.py (WARNING)

Invalid config for [automation]: required key not provided @ data[‘trigger’][1][‘platform’]. Got None. (See /config/configuration.yaml, line 13).

20:28:24 – config.py (ERROR) - message first occurred at 20:28:24 and shows up 2 times

- id: '1577621191351'
  alias: turn on aquarium lights
  description: ''
  trigger:
  - at: 08:14:00
    platform: time
  condition: []
  action:
  - device_id: 38d69e8980c44cba97eff3b140b22b93
    domain: switch
    entity_id: switch.sonoff_basic_relay3
    type: turn_on
- id: '1577621266638'
  alias: Turn Off Aquarium Light
  description: ''
  trigger:
  - at: '21:00'
    platform: time
  condition: []
  action:
  - device_id: 38d69e8980c44cba97eff3b140b22b93
    domain: switch
    entity_id: switch.sonoff_basic_relay3
    type: turn_off
- id: '1577869506263'
  alias: D1 board time test
  description: ''
  trigger:
  - platform: time_pattern
    seconds: /30
  condition: []
  action:
  - device_id: 92aaf6feb5e04162a2beb040e422d226
    domain: switch
    entity_id: switch.d1_pin12
    type: toggle
- id: '1577870376271'
  alias: D1_Board2
  description: ''
  trigger:
  - platform: time_pattern
    seconds: /2
  condition: []
  action:
  - entity_id: switch.d1_pin2
    service: switch.toggle
- id: '1585255113954'
  alias: GreenHouse Centre Bed MainPump
  description: '# 8'
  trigger:
  - minutes: /50
    platform: time_pattern
  condition:
  - after: sunrise
    before: sunset
    condition: sun
  action:
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_on
  - delay: 00:14:00
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_off
- id: '1588956061523'
  alias: CentreBed Night Pump
  description: ''
  trigger:
  - hours: /2
    platform: time_pattern
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_on
  - delay: 00:15:00
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_off
- id: '1591085891848'
  alias: Night LED
  description: ''
  trigger:
  - event: sunset
    platform: sun
  condition: []
  action:
  - device_id: 92aaf6feb5e04162a2beb040e422d226
    domain: switch
    entity_id: switch.d1_pin3
    type: turn_on
- id: '1591132881735'
  alias: Night Led OFF
  description: ''
  trigger:
  - event: sunrise
    platform: sun
  condition: []
  action:
  - device_id: 92aaf6feb5e04162a2beb040e422d226
    domain: switch
    entity_id: switch.d1_pin3
    type: turn_off
- id: '1591133049893'
  alias: Sculpture Control
  description: ''
  trigger:
  - entity_id: sensor.dark_sky_temperature
    for: '5'
    from: '10'
    platform: state
    to: '20'
  condition: []
  action:
  - device_id: 0cd34757b437408f930c3b7d3ef3fb4b
    domain: light
    entity_id: light.led_sculpture
    type: flash
- entity_id: 'sundown.flasher'
  alias: led Sun indicator
  trigger:
  - seconds: /30
    platform: time_pattern
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - device_id: 92aaf6feb5e04162a2beb040e422d226
    domain: switch
    entity_id: switch.d1_mosfet
    type: turn_on
  - delay: 00:00:05
  - device_id: 92aaf6feb5e04162a2beb040e422d226
    domain: switch
    entity_id: switch.d1_mosfet
    type: turn_off

just to add the line 13 referenced is

tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

line 13 is the line begining with group:.
the groups.yaml is empty

You’re missing the condition: line again:

- id: '1588956061523'
  alias: CentreBed Night Pump
  description: ''
  trigger:
  - hours: /2
    platform: time_pattern
  condition: # <===================== You were missing this
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_on
  - delay: 00:15:00
  - device_id: a91d26c766e0421f90e46869349792d1
    domain: switch
    entity_id: switch.centrebed_main_feed_pump
    type: turn_off

Excuse my lack of checking.
Fantastic my code is working!
To get my 50mins and variable timings I think i need to understand timers is that right? and that will be another topic.
Thanks again.
Keith

Not necessarily. If you add sensor.time to your configuration, you could do something like this:

- trigger:
  - platform: template
    value_template: >
      {% set n = states('sensor.time').split(':') %}
      {{ (n[0]|int*60 + n[1]|int) % 50 == 0 }}

And the period could come from an input_number instead of being hard coded.

Or you could use a timer. There’s probably several ways to do it.