Distinguish if switch is turned on by automation, or manualy

Hi. Hassio with conbee and deconz. Power plug innr sp120. Power plug has manual turn on / off button. Requirement is to turn on and off during specific time events. And if it is turned on manually then turn it of after two hours.

My approach:

  - alias: TowelHeater ON
    trigger:
    - platform: time
      at: '05:00:00'
    condition:
        condition: time
        weekday: [mon, tue, wed, thu, fri]
    action:      
      service: homeassistant.turn_on #switch.turn_on
      entity_id: 
        - switch.TowelHeater
        - input_boolean.TowelHeater_onbyautomation
    
      
  - alias: TowelHeater OFF    
    trigger:
    - platform: time
      at: '06:50:00'
    condition:
        condition: time
        weekday: [mon, tue, wed, thu, fri]
    action:
      service: homeassistant.turn_off #switch.turn_off
      entity_id: 
        - switch.TowelHeater
        - input_boolean.TowelHeater_onbyautomation
        
        
  - alias: TowelHeater outlet on event
    trigger:
    - platform: state
      entity_id: switch.TowelHeater
      from: 'off'
      to: 'on'
    condition:
      condition: state
      entity_id: input_boolean.TowelHeater_onbyautomation
      state: 'off'
    action:
    - service: notify.myHomenotify
      data_template:
        message: "Towel heater manual outlet event {{ trigger.to_state.state }} triggered for 2 hours" #trigger.to_state.state - only state (on / off) output
    - delay: '02:00:00'  
    - service: homeassistant.turn_off #switch.turn_off
      entity_id: switch.TowelHeater

Questions:

  1. Can I do it without input_boolean.TowelHeater_onbyautomation ?
  2. Any general logic comments. It also works quirky sometimes: when turning on it turns of within few seconds
  3. Can I make this part as separate method and call it with one line on other automations:
    - service: notify.myHomenotify
    data_template:
    message: “Towel heater manual outlet event {{ trigger.to_state.state }} triggered for 2 hours” #trigger.to_state.state - only state (on / off) output

Why not have an automation to always turn off the heater if it has been on for 2 hours?

That works for your auto (which seems to run for 1hr 50 minutes) or manual turning on.

Rather than a long delay hanging open from turn on, just have a trigger of the heater being on for 2 hours (or whatever duration you want), with the action to turn it off.

There is a trigger, which could measure if heater is on for two hours? Can you tip me a bit more about it?

Have a look at at the state trigger example for automation

You want to test for state on for 2 hours - very like the example.
No conditions
Then action - turn off the switch

This assumes the state machine in HASS gets updated to know the switch is on if it is turned on manually.

1 Like

O.k. thanks! :slight_smile: