Choose time to run automaton

I have this automation to turn on outside lights at sunset. Can I include another condition to turn off lights at sunrise. Can it be as one automation?

- id: 'Outdoor Lights Automation'
  alias: Outdoor Lights Automation
  trigger:
    platform: sun
    event: sunset
  action:
  - service: light.turn_on 
    entity_id: light.outside_all_around
  - service: light.turn_on
    entity_id: light.outside_wall

Would this work?

- id: 'Outdoor Lights Automation'
  alias: Outdoor Lights Automation
  trigger:
    platform: sun
    after: sunset
    offset: "-00:30:00"
    before: sunrise
  action:
  - service: light.turn_on 
    entity_id: light.outside_all_around
  - service: light.turn_on
    entity_id: light.outside_wall

No. Your sun platform trigger options are not correct.

Use two automations.

- id: outdoor_lights_on
  alias: 'Outdoor Lights On'
  trigger:
    platform: sun
    event: sunset
    offset: '-00:30:00'
  action:
  - service: light.turn_on 
    entity_id: light.outside_all_around
  - service: light.turn_on
    entity_id: light.outside_wall
- id: outdoor_lights_off
  alias: 'Outdoor Lights Off'
  trigger:
    platform: sun
    event: sunrise
  action:
  - service: light.turn_off
    entity_id: light.outside_all_around
  - service: light.turn_off
    entity_id: light.outside_wall

Anyway to combine those two automations into 1 automation?

Yes but I would not recommend it.

This way is simple and easy to understand when you come back to it in 3 months time.

Thanks!

How can I make this into a 12 hour AM/PM format for the start automation at. I know how to do it for the current time, but not for the input time. My template is coded to show 12 hour time, but the card still displays 24 hours

    value_template: '{{ states(''sensor.time'') == (states.input_datetime.set_time.attributes.timestamp
      | int | timestamp_custom(''%-I:%M %p'', False)) }}'

Capture

This value template doesn’t make any sense to me, this really works? Your template compares if the time from sensor.time is equal to the time of the converted timestamp from the input_datetime, so it should return either True or False and not a time.

Try this:

value_template: "{{ state_attr('input_datetime.set_time', 'timestamp') | timestamp_custom('%-I:%M %p', False) }}"

I implemented your value_template, but the time still shows in 24 hours.
Capture

Oh, I overread that you want to change the input_datetime. I don’t know and also don’t think that this is possible as you would need to change the config of the input_datetime and this has no option for 12AM/PM format.

Could it be done with a drop down menu input_select?

Maybe, but I don’t think so. Maybe you can create the options for the input_select how you want them and then use a value_template to somehow translate your selected value into a readable format for the automation.

So no matter what home assistant will need the time format for the input_datetime.set_time or input_select.set_time to be in 24 hour format?

For the input_datetime yes, for the input_select you can choose whatever you want, however the automation etc. will not be able to read the value directly, hence the value_template to convert it to a readable format.

So these two automatons don’t fire. The lights don’t turn on when the sun sets. However, they work when I manually trigger them. I did check that both automations are on in the states page. Maybe it’s best to use entity_id: sun.sun state: below_horizon?

- id: outdoor_lights_on
  alias: 'Outdoor Lights On'
  trigger:
    platform: sun
    event: sunset
    offset: '-00:30:00'
  action:
  - service: light.turn_on 
    entity_id: light.outside_all_around
  - service: light.turn_on
    entity_id: light.outside_wall
- id: outdoor_lights_off
  alias: 'Outdoor Lights Off'
  trigger:
    platform: sun
    event: sunrise
    offset: '+00:30:00'
  action:
  - service: light.turn_off
    entity_id: light.outside_all_around
  - service: light.turn_off
    entity_id: light.outside_wall```
  1. Is your location set correctly?
  2. Is your time and timezone set correctly?
  3. Do you have the default config or sun platform in your configuration.yaml file?
  4. What errors do you see in the log related to this?

This is how my configuration.yaml file looks like. I have default config in it, but no location.


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

# Z-Wave Stick
zwave:
   usb_path: /dev/ttyACM0
   
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensor.yaml

input_datetime:
  set_time:
    name: Set Time
    has_date: false
    has_time: true

That could be because you set your time and location using the new onboarding method.

Check the configuration / general menu.

Seems correct to me.

This is all I see in the logs

Error doing job: Task exception was never retrieved
5:17 PM /usr/src/homeassistant/homeassistant/core.py (ERROR)
Error handling request
1:23 PM /usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py (ERROR) - message first occurred at 1:23 PM and shows up 2 times
remove:Group 'all_scripts' doesn't exist!
10:38 AM components/group/__init__.py (WARNING)
Z-Wave not ready after 300 seconds, continuing anyway
10:37 AM components/zwave/__init__.py (WARNING)
Z-Wave entity Unknown Node 7 Level (node_id: 7) not ready after 31 seconds, continuing anyway
10:33 AM components/zwave/__init__.py (WARNING)
Z-Wave node 7 not ready after 30 seconds, continuing anyway
10:33 AM components/zwave/__init__.py (WARNING)

So the outside lights automation worked last night, but the automation below did not. I checked the state of the input, and it does show the correct set time, but the automation won’t fire. It works only when I manually trigger the automation. The logbook does not show that the automation is triggered.

- id: Set Time
  alias: Set Time
  trigger:
    platform: template
    value_template: '{{ state_attr(''input_datetime.set_time'', ''timestamp'') | timestamp_custom(''%I:%M
      %p'', False) }}'
  action:
  - service: light.turn_off
    entity_id: group.lightsoff
  - service: light.turn_on
    entity_id: group.lightson
    data:
      brightness_pct: 50