Choose time to run automaton

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

Two things,

  1. Your quoting is all messed up. Put double quotes outside the template, single quotes inside (not double single quotes).
  2. Your template resolves to h:MM PM/AM. Templates need to resolve to true or false to trigger. You need to compare the input_datetime to the time.

So:

Add a time sensor if you have not already:

sensor:
  - platform: time_date
    display_options:
      - 'time'

then try this:

  trigger:
    platform: template
    value_template: "{{ states('sensor.time') == states('input_datetime.set_time')[0:5] }}"

If you put this in the developer tools template editor you will see what it does:

time now = {{ states('sensor.time') }}

input_datetime = {{ states('input_datetime.set_time') }}

formatted input_datetime = {{ states('input_datetime.set_time')[0:5] }}

template result = {{ states('sensor.time') == states('input_datetime.set_time')[0:5] }}

Here’s an example using one of my input_datetimes:

1 Like

FYI, double single quotes is allowed in yaml. I too made that mistake a year or so ago. So his quoting is valid, but the trigger not resolving to True/False is the real problem.

Escaped single quotes by single quotes are an unnecessary affront to common sense. There are saner alternatives. Why do this?

Do not teach people this except where absolutely necessary.

1 Like

The above absolutely makes more scene. This was a stupid mistake on my part. I was concentrating on the action portion of the automation, not the trigger. I updated the trigger and will test it out tonight.

Hi

I suffer from similar issue. The set input is triggering at the wrong time.
I’ve read this thread, but did not reached a solution. I hope I didn’t miss something.

My setup:

I have a time sensor

sensor:
  - platform: time_date
    display_options:
      - 'time'

And an automation script (which uses the ‘true’ in the template’s time stamp comparison)

- id: '1587744513372'
 alias: 'power on on time '
 description: ''
 trigger:
   platform: template
   value_template: "{{ states('sensor.time') == (state_attr('input_datetime.amit_s_light', 'timestamp') | int | timestamp_custom('%H:%M', True)) }}"
 action:
 - device_id: bc37ba8b5a0c49e690fb1a1e11eb9c49
   domain: light
   entity_id: light.desk_lamp
   type: turn_on

I have set my local time zone and geographical location
I see the “correct” UTC time on the home assistant overview page, however, the set time in the input_datetime is triggered 2 hours after the expected time (i.e. if I want to get the trigger at 11:00, I have to set it to 9:00)
I’m living at UTC+2 (which might fit the 2 hours difference) however currently we are at GMT+2+DST, a 3 hours difference from GMT.
I’ve checked the automation itself and the action is working when triggered manually.

Any ideas? further debug steps? I’m newbie here and doesn’t have a debug environment on my computer.

Thanks
Ariel

@tom_l Thanks Mate ! Your simple solution works for me. I applied it verywhere now, where the WAF highly increased, since the wife can now easily change the timing of “her” lights herself …

grtz
John

1 Like

Assuming your input_datetime has time: true and has date: false
Then you should simplify your template to work with text and bypass the utc and timestamp considerations.
Timestamp is always utc aware.

"{{ states('sensor.time') == states('input_datetime.amit_s_light') [0:5] }}"

This will always work in local time (I can’t think why anyone would ever want to consider dst offsets or utc in a home automation context but I’m sure someone will be able to come back with one)

1 Like

Hey guys, I’m trying to add multiple time boxes but for some reason only the first default ones show up I’m unsure why. Could someone point me in correct direction please…

config/Input_datetime.yaml

WORKING ONES

both_date_and_time:
  name: Input with both date and time
  has_date: true
  has_time: true
only_date:
  name: Input with only date
  has_date: true
  has_time: false
only_time:
  name: Input with only time
  has_date: false
  has_time: true
NOT EVEN SHOWING IN DEVELOPER

boys_light_off_time:
  name: boys Light off time
  has_date: false
  has_time: true
set_time:
  name: Set Time
  has_date: false
  has_time: true


dt1:
  name: Date Time 1
  has_date: true
  has_time: true
  initial: "2019-05-01 07:30"

did you restart after adding them? FYI if you don’t want to restart, move to the UI

or did you move to the UI and forget? Check configuration.yaml for the include on the input_datetime.

Lol for some reason Hass was having issues reading the input_datetime.yaml file renamed and now works crazy the simple things can be allusive. Thanks for help