Problem in automation - help

i’m triyng to automate a switch.
The trigger is ok… it works every minute… in the action i have problems,
it works on the wrong minute… my code:

(automation.yaml)

- id: '1583526600964'
  alias: piscina_bomba_auto
  trigger:
  - platform: time_pattern
    minutes: /1
  action:
  - entity_id: switch.sonoff_10009ace1f
    service_template: "{% if states.sensor.time.state == states.input_datetime.h_pb_on_3b.state\
      \ %}\n  switch.turn_on\n{% else %}\n  switch.turn_off\n{% endif %}\n"

the problem is:

  • i have set the input_datetime.h_pb_on_3b = 10:30 for example
  • the trigger shoots every minute
  • the switch only change to ON at 10:31
  • at 10:30 trigger… if the switch is ON it changes to OFF, and at 10:31 to ON again

i want at datetime.h_pb_on_3b.state turn the switch_on… not one minute later

Thanks

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

Try this:

- id: '1583526600964'
  alias: piscina_bomba_auto
  trigger:
    platform: template
    value_template: "{{states('sensor.time') == states('input_datetime.h_pb_on_3b')}}"
  action:
    service: switch.turn_on
    entity_id: switch.sonoff_10009ace1f

hi, Thanks for you sugestion

with your sugestion i only can the switch ON

i have several input_datetime to interact to
Capturar
i want to On or Off the switch in the same automation… comparing the time.state with all my input_datetime values

my ideia is:

  • every second
  • compare all input_datetime values with time.state
  • and switch ON or OFF or nothing… as action

any one sugest any soluction?

nice to learn in this community
Thanks to 123 Taras

Your original automation is triggered every minute. So it turns on the switch at the desired time and turns it off for every other time. That means the switch is turned on for just one minute and then turned off. Is that how you want it to work?

An input_datetime only stores the time. How do you plan to tell the automation that the switch should be turned on or off at the specified time?

Why check every second if the time you’re specifying is in hours and minutes?

sensor.time changes every minute. That’s adequate for most scheduling applications.