Specific time and day set up?

Hello, is there way to make automation in which to set specific time in weekdays and weekends ?
I want to make my water heater to turn on and off 3 times in specific time during the weekdays and to turn on in other time during the weekend ?

Thanks. I made schedule but probably something is wrong with my automation because it only turns on water heater but not turning it off when schedule time ends. Can you help me. I want to turn on/off in the schedule time and to be active only when I and me wife are in Sofia city. This is my yaml. Probably my action must be water heater “toggle” not “turn on” ?

alias: water heater
description: ""
trigger:
  - platform: state
    entity_id:
      - schedule.water_heater_scedule
condition:
  - condition: or
    conditions:
      - condition: zone
        entity_id: device_tracker.anelis_iphone
        zone: zone.in_sofia
      - condition: zone
        entity_id: device_tracker.mutkos_iphone
        zone: zone.in_sofia
action:
  - type: turn_on
    device_id: 503857c51fe1e6affa87f28476dcc045
    entity_id: switch.water_heater_switch_1
    domain: switch
mode: single 

Please format your code so we can read it.

sorry, now it is formated

Nothing in your automation is calling a turn_off service.

You’ll need to create another automation that checks that you’re both not in that zone, and then turns it off.

i do not want to turn off when we are not in the zone. i want to turn on and off in specific time which i add in the schedule helper. I want if we are in zone to turn on at 1 pm and turn off at 2:30 pm , at 8pm turn on and turn off at 9:30 pm at the weekdays and almost hole day in the weekend. And if we are on vacantion and we are not in the zone to not turn on which i check with the condition for the zones. here is my schedule time helper

Then you still need a turn off automation

with toggle action it is working but when i turned it on manually by the wall switch then the automation it is reversed and when it have to be on it is off.
How it must be with two automations ? Again with state trigger for the Schedule and to set “From” and “TO” and then the action to be turn on and in the other automation off ?

You could use a choose block so that if the schedule is on it turns the heating on, and if off it turns it off.

You could use templates to make it work both ways and use the zone entity to know if anyone is in_sofia.

alias: water heater
description: ""
trigger:
  - platform: state
    entity_id:
      - schedule.water_heater_scedule
condition:
  - condition: numeric_state
    entity_id: zone.in_sofia
    above: 0
action:
  - type: "turn_{{ trigger.to_state }}"
    device_id: 503857c51fe1e6affa87f28476dcc045
    entity_id: switch.water_heater_switch_1
    domain: switch
mode: single 
1 Like

probably i am mistaking something because i’m newbie but i’ve got error with this code

Sadly device actions don’t work with templates, though the concept is fine if you switch to using service calls

Also your indenting is a mess.

Your indentation is off.
Indent - condition: numeric_state one space

alias: water heater
description: ""
trigger:
  - platform: state
    entity_id:
      - schedule.water_heater_scedule
condition:
  - condition: numeric_state
    entity_id: zone.in_sofia
    above: 0
action:
  - service: "switch.turn_{{ trigger.to_state }}"
    target:
      entity_id: switch.water_heater_switch_1
mode: single

That should work

Change this:

  - service: "switch.turn_{{ trigger.to_state }}"

to this:

  - service: "switch.turn_{{ trigger.to_state.state }}"
1 Like

I have these errors when the automation turns on. I couldn’t see if the water heater turns on because it was on when the automation starts, but at least it does not turn off. After 20 minutes i will see if it will turn off because i add another time for test in my schedule. But i am curios what these errors are ?

2023-02-13 16:00:00.009 ERROR (MainThread) [homeassistant.components.automation.water_heater] Water heater turns on when someone is in Sofia: Error executing script. Error for call_service at pos 1: Template rendered invalid service: switch.turn_<state schedule.water_heater_schedule=on; editable=True, next_event=2023-02-13T16:30:00+02:00, icon=mdi:thermometer-water, friendly_name=Water heater schedule @ 2023-02-13T16:00:00.001064+02:00>
2023-02-13 16:00:00.015 ERROR (MainThread) [homeassistant.components.automation.water_heater] Error while executing automation automation.water_heater: Template rendered invalid service: switch.turn_<state schedule.water_heater_schedule=on; editable=True, next_event=2023-02-13T16:30:00+02:00, icon=mdi:thermometer-water, friendly_name=Water heater schedule @ 2023-02-13T16:00:00.001064+02:00>

Thanks, i will try it because the previous code does not work

it does not work. i have these error when i try to run from the menu because the automation did not start itself in the specified time schedule.

2023-02-13 17:05:18.359 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'to_state' when rendering 'switch.turn_{{ trigger.to_state.state }}'
2023-02-13 17:05:18.366 ERROR (MainThread) [homeassistant.components.automation.water_heater] Water heater turns on when someone is in Sofia: Error executing script. Error for call_service at pos 1: Error rendering service name template: UndefinedError: 'dict object' has no attribute 'to_state'
2023-02-13 17:05:18.369 ERROR (MainThread) [homeassistant.components.automation.water_heater] Error while executing automation automation.water_heater: Error rendering service name template: UndefinedError: 'dict object' has no attribute 'to_state'

How did you test the automation?

The trigger variable will be undefined if the automation was not triggered by its State Trigger. So if you executed the automation via its Run command, it will result in an error (like the one you received).

Reference: Testing your automation

1 Like