Can a manual activation of a switch override an automation?

Can I create an automation that is triggered by a wemo switch button press that will suspend another automation until that device is manually or automatically turned off?

Example… I have a small space heater in my old houses bathroom. I like to run it in the morning while in the shower. But, I have an automation that looks at the temperature in the bathroom and if warm enough it turns off the heater, overriding the manual activation. I could set times that he automatic control will not be active, but that is not good for our house since others may shower at different times of the day.

So, I am looking for something like this:

action: automation.blah_off
action:
  service: homeassistant.turn_off
  entity_id: automation.blah

Wow, that really is a thing! I had not found it yet in the docs, was not sure it existed. Thanks a bunch!!!

- service: automation.turn_on
  entity_id: automation.doors

works also. Do you know the difference between homeassistant.turn_off and automation.turn_off?

I do not… I assume it is fairly subtle?

homeassistant.turn_off works for many domains, basically any domain that has a turn_off service. You could use it for lights, switches, automations, etc. This can be very helpful if you want to turn off or on a mixed group (e.g. a group.living_room that has lights and switches). Obviously, you can only use automation.turn_off to turn off automations.

1 Like

As @Dolores says, it’s like a catch all for turn_on and turn_off (and possibly toggle). I find it easier to just use it for everything I can and then only component specific services (which are usually one offs) use their own services. Makes it quicker for me anyway :+1:

1 Like

This is good to know. I love this forum, every question is a learning experience. I am also amazed at how much can be accomplished on an RPi2.

I have a large number of automatons, some are fairly complex conditional automations that are supplemented by some fairly simple automatons on the same device or group. I am to the point that I am afraid that I am going to have to get much more complex to properly do what I want to do.

For example this one heater needs to do the following:

  1. turn on between 5:55 and 7:00 am, if it is below 55 outside. May be manually turned off at an earlier time. Good shower time
  2. turn on when the room is below 65 based on an mqtt sensor in the room
  3. turn off when the room is above 65
  4. turn off after 1.5 hours regardless of the situation
  5. turn on and run if turned on manually, until 1.5 hours have passed or until turned off manually.

I have ended up in a state where the first automation fires and the second and third interrupt it. I think I have it fixed thanks to the above tips. I would like to be able to detect a button press on the wemo switch and override all but number 4. So, I need to differentiate between a button press and the automatons number 2 & 3 to make this happen. Will have to dig deeper. I am beginning to wonder if one giant automation might be the answer with or’s and and’s.

You should be able to do this with five automations. It’s a lot of them but I don’t think that it will be too ugly.

a. Matches automation 1 as you described, with the addition of turning on an input boolean. (e.g. input_boolean.shower_time)
b. Matches automation 2 as you described, with the addition of turning on an input boolean (e.g. input_boolean.auto_heat ). Add a small delay before turning on this input_boolean.
c. Matches three as you described, but checks if input_boolean.shower_time is off. and if input_boolean.auto_heat is on. If true, turn off the heater.
d. Matches automation 4 as you described, using the state trigger with a “for 90 minutes” specification. This will also handle automation 5.
e. New automation: On a state change of the wemo switch, turn off input_boolean.auto_heat. If a person did this, it will effectively disable automation c. The next time the heat automatically kicks in, (based on automation b), it will re-enable the temperature based control.

Perhaps someone else has a recommendation for how to clean this up a bit, but I think it will be clean (except for perhaps automation e).

I make that 2 automations…

First one triggers whenever the heater is switched on, action is delay 90 minutes and switch off. That takes care of 4 and 5.

Second one has a two time triggers and a template trigger, time triggers are 5.55 and 7am, template is temperature. Action is a service template, if 5.55 or below 65 degrees switch on, if 7am or above 65 degrees switch off.

Sorted.

I have not ever used input_boolean. I will have to look into this. I may comment out all of my existing autos for this device and ask for opinions… Would that be to much to ask for?

I will have to ponder on this… I currently have 7 autos to come very close to what I wanted to do… Will have to read again on templates and look for some examples.

Lots of people would use node-red or appdaemon for this sort of thing tbh.

I have thought about installing appdaemon, not sure what node-red is…

Have a quick search of the forums, I don’t use it myself but there are lots of examples and some very happy users.

It takes a seperate system from the Hassio install? That is what I have gotten in the past anyway. Will look deeper, some of these autos are a PITA. I do like to run with no external dependencies, such as other systems or cloud apps or services.

Thanks for your time, I know I have told you that before! I am up to around 30 autos and am getting a feel for all of it except templates and still trying to figure out when to use service calls. I really like Hassio, I can see at some point it might be good to get away from the closed environment, but is has been good for learning.

I have also enjoyed building my own Wemos based sensors and working with the Sonoff’s and Tasmota.

1 Like

Node-Red or AppDaemon will run on the same hardware as ‘add-ons’. Just like the other add-ons you probably rely on, it wouldn’t really be any more risk than the current hassio you are using.

1 Like

Ok, so I have created an input_boolean starting with the state off. I am using it to index the various automatons and it seems to work well. But, I have one problem… how do I set it’s state to on when I turn the heater on in the UI or when someone presses the button on the wemo?

I do not think I can do it with a state from off to on in a simple state checker because some of the automations may try to change it back based on condition… Maybe I am overthinking it and should use a state change. Would that actually work?

This is what I now have for my set of automations…

##########################################
#                                        #
#     Automations for Bathroom Heat      #
#                                        #
##########################################
- id: "Bathroom heat on at 05:55 weekdays if cold"
  alias: 'Bathroom heat on at 05:55 weekdays if cold'
  trigger:
    - platform: time
      at: '05:55:00'
  condition:
    condition: and
    conditions:
      -  condition: time
         weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
      - condition: numeric_state
        entity_id: sensor.pws_temp_f
        below: 55
  action:
  - service: switch.turn_on
    data:
      entity_id: switch.bathroom_heater
  - service: homeassistant.turn_off
    data:
      entity_id: automation.bathroom_heat_on_timer_room_warm
  - service: input_boolean.turn_on
    data:
      entity_id: input_boolean.notify_bathroom_heat

- id: "Bathroom heat off at 07:00"
  alias: 'Bathroom heat off at 07:00'
  trigger:
    - platform: time
      at: '07:00:00'
  action:
  - service: switch.turn_off
    data:
      entity_id: switch.bathroom_heater
  - service: homeassistant.turn_on
    data:
      entity_id: automation.bathroom_heat_on_timer_room_warm
  - service: input_boolean.turn_off
    data:
      entity_id: input_boolean.notify_bathroom_heat

- id: "Bathroom heat on for to long"
  alias: 'Bathroom heat on for to long'
  trigger:
    platform: state
    entity_id: switch.bathroom_heater
    from: 'off'
    to: 'on'
    for:
      hours: 1
      minutes: 30
  action:
    - service: switch.turn_off
      entity_id: switch.bathroom_heater
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.notify_bathroom_heat

- id: "Bathroom heat on timer room cold"
  alias: 'Bathroom heat on timer room cold'
  trigger:
    - platform: time
      minutes: '/5'
      seconds: '00'
# Trigger every X minutes, "/" causes repeating trigger
    - platform: numeric_state
      entity_id: sensor.temperature3
      below: '63'
      for:
        minutes: 2
# Trigger based on WU temp below X and has been for Y minutes
  condition:
    condition: and
    conditions:
      - condition: numeric_state
        entity_id: sensor.temperature3
        below: '63'
# Verify WU temp below X
      - condition: state
        entity_id: switch.bathroom_heater
        state: 'off'
      - condition: state
        entity_id: input_boolean.notify_bathroom_heat
        state: 'off'
# Verify switch is really off
  action:
    - service: switch.turn_on
      data:
        entity_id: switch.bathroom_heater
#    - service: notify.sms_matt
#      data:
#        title: "Warning"
#        message: "Bathroom heat on"
# Set switch to correct state "ON"

- id: "Bathroom heat off timer room warm"
  alias: 'Bathroom heat on timer room warm'
  trigger:
    - platform: time
      minutes: '/5'
      seconds: '00'
    - platform: numeric_state
      entity_id: sensor.temperature3
      above: '63'
      for:
        minutes: 2
  condition:
    condition: and
    conditions:
      - condition: numeric_state
        entity_id: sensor.temperature3
        above: '63'
      - condition: state
        entity_id: switch.bathroom_heater
        state: 'on'
      - condition: state
        entity_id: input_boolean.notify_bathroom_heat
        state: 'off'
  action:
    - service: switch.turn_off
      data:
        entity_id: switch.bathroom_heater

The more I study this the more I realize that all I have to do is to change the boolean state when it is manually turned on…

2 Likes