Automation triggering reliability issues and triggering the wrong automation

Hello folks - seasons greetings!

I am having the most trouble getting some automations set up for my Zwave immersion heater controller (Horstmann SIR321). To all instents and purposes, it is a relay/switch so the only thing that can be done with its entity is Turn on/Turn off.

Background

I have most of the basic building blocks working but there are some niggles that I am struggling to debug. Most of what is working has been copy and pasted from the cookbook/the forum.

My primary goals for the water heater and HA are as follows:

  • Have a button in Lovelace which when pressed puts the water heater on for 1 hour
  • Trigger the water heater to come on for one hour at a different time each day of the week (also from Lovelace)

This screenshot shows what the front end looks like:

The code for the cards looks like this:

- badges: []
    cards:
      - entities:
          - switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
        show_header_toggle: false
        title: Immersion Heater Status
        type: entities
      - entity: automation.hot_water_on_one_hour
        hold_action:
          action: none
        icon: 'mdi:thermometer-lines'
        name: Boost hot water for 1 hour
        show_icon: true
        show_name: true
        tap_action:
          action: call-service
          service: automation.trigger
        type: entity-button
      - entities:
          - entity: input_datetime.hws_mo
          - entity: input_datetime.hws_tu
          - entity: input_datetime.hws_we
          - entity: input_datetime.hws_th
          - entity: input_datetime.hws_fr
          - entity: input_datetime.hws_sa
          - entity: input_datetime.hws_su
        show_header_toggle: false
        title: Water heater schedule
        type: entities
    path: hot-water
    title: Hot Water

At the back end I have the following automations:

  • Hot Water On - One Hour
    Turns the heater on
    [Send a notification to my phone for debugging]
    Delays for an hour
    Turns it off
  • Hot water - Monday
    Use a template, a time sensor and input entitiy to evaluate the current time
    Check a condition to see if it is the right day of the week
    Trigger the Hot Water On - One Hour automation
    [Send a notification to my phone for debugging]

Once this is working, it is my intention to have further automations which cover the other days of the week

Automations.yaml looks like this:

- id: '1571092941517'
  alias: Hot Water On - One Hour
  description: Switches the water on for 1 hour at any time
  trigger: []
  condition: []
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - data:
      message: automation triggered  - Hot Water On - One Hour
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off
- id: '1577119893046'
  alias: 'DEBUG: Hot water switch on'
  description: ''
  trigger:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    platform: device
    type: turned_on
  condition: []
  action:
  - data:
      message: water heater on
    service: system_log.write
- id: '1577120792510'
  alias: 'DEBUG: Hot water switch off'
  description: ''
  trigger:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    platform: device
    type: turned_off
  condition: []
  action:
  - data:
      message: water heater off
    service: system_log.write
- id: '1577124991290'
  alias: Hot water - Monday
  description: Monday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_mo.attributes.tim>
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - mon
  action:
  - data:
      entity_id: automation.hot_water_on_one_hour
    service: automation.trigger
  - data:
      message: Monday automation triggered
    service: notify.notify

For debugging I have two extra automations that write to the log what the switch is doing.

All automations have been tested in isolation, if they are triggered by clicking the ‘Trigger’ button in the (i) card for each automation they work properly:

For reference this is my configurations.yaml file:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Ossy
  # Location required to calculate the time the sun rises and sets
  latitude: !secret
  longitude: !secret
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 0
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/London
  # Customization file
  customize: !include customize.yaml

# 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

# Discover some devices automatically
discovery:

# Sensors
sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'time_date'
      - 'time_utc'
      - 'beat'
  # Weather prediction
  - platform: yr


# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

#Entity Variables

#Hot water timer inputs
input_datetime:
  hws_mo:
    name: Set time for water heater (Monday)
    has_date: false
    has_time: true

  hws_tu:
    name: Set time for water heater (Tuesday)
    has_date: false
    has_time: true

  hws_we:
    name: Set time for water heater (Wednesday)
    has_date: false
    has_time: true

  hws_th:
    name: Set time for water heater (Thursday)
    has_date: false
    has_time: true

  hws_fr:
    name: Set time for water heater (Friday)
    has_date: false
    has_time: true

  hws_sa:
    name: Set time for water heater (Saturday)
    has_date: false
    has_time: true

  hws_su:
    name: Set time for water heater (Sunday)
    has_date: false
    has_time: true


  • Hot Water On - One Hour - expected behaviour: water switch goes on, notification arrives to phone, water goes off after one hour
  • Hot water - Monday - expected behaviour: water switch goes on, notification arrives to phone, water switch goes on, second notification arrives to phone from nested automation trigger, water goes off after time delay

I am aware that triggering in this way ignores conditions. The time based automation has also been tested and fires at the right time if the day is correct.

For reference I am running HA inside a docker container. Docker is running on Unbuntu 18 on an NUC, I got it up and running using this tutorial: Absolute Beginners guide to installing HA on Intel NUC using Docker and since then have added samba and git to the docker container where HA runs. I’m not sure if further details are relevant, please let me know if they might be useful.

The system is running Home Assistant 0.100.1
Frontend version: 20191002.2 - latest

System Health

arch x86_64
dev false
docker true
hassio false
os_name Linux
python_version 3.7.4
timezone Europe/London
version 0.100.1
virtualenv false

Lovelace

mode storage
resources 0
views 3

Issues

In practice, however, things are not so good. I currently have the following issues with my set up:

  • When pressing the ‘Boost hot water for 1 hour’ button in lovelace behaviour is inconsistent.
    —Pressing the button causes the ‘Monday’ automation to fire, a ‘Monday’ notification arrives to my phone
    ------It would seem that the button is mapped to the wrong trigger but it isn’t
    —Sometimes, the water switch does toggle over and sometimes it doesn’t
    —When the switch does activate from this button press, three notifications arrive to my phone, one for ‘Monday’ and two for ‘one hour boost’ (I presume this is one from the actual entity call and one from the nested call inside the monday automation).

  • When the ‘Monday’ automation is triggered by the correct date and time, sometimes it calls the ‘one hour boost’ automation trigger and sometimes it doesn’t.

Three notifications from one button press:

More simply:

  • The entity card in lovelace seems to be calling the wrong automation
  • The time based automation intermittently doesn’t call the 1 hour automation in its action

All of which results in some early morning cold showers that are pretty unpleasant!

Questions

All this in mind, I would really appreciate some pointers on the following things:

  • Is there something wrong with my set up that I have missed?
  • What might be causing the intermittent behaviour of automation making them unreliable?
  • How do you go about debugging something like this, the logs and so on have no shown me anything that I can use to progress
  • Would it be better to just have on-delay-off actions in each of my day-of-the-week automation, instead of calling another automation trigger (this feels like duplicating code but maybe that’s ok in this instance)

Any tips much appreciated!
Many thanks and warm regards,
D

Your first automation has no trigger defined.

- id: '1571092941517'
  alias: Hot Water On - One Hour
  description: Switches the water on for 1 hour at any time
  trigger: []
  condition: []

Hey there!

Yes, you’re correct that automation has no trigger of its own - it is my intention to have that automation only run when manually triggered or when called by another automation.

As it was kinda working I didn’t think that automations must have a trigger defined - is this the case?

If this is true then:

  • Is there some dummy trigger I can use to fill this section in but it never actually happens?
  • Should I be using a script/scene/something else to achieve my end goal here or is having one automation call another one OK?
  • Is using the automation.trigger service from an entity card the ‘right’ way to get my button press to work or is there a more elegant solution?

As a test, I have added an input boolean ‘hot water enable’ which the 1 hour trigger now looks for as its trigger. It doesn’t seem to do anything (if I go into the dev tools and change the state of the boolean from off to on and back again the automation doesn’t trigger).

This in it self doesn’t really matter as I didn’t want it to trigger based on that boolean but defining a trigger for that automation didn’t change the behaviour of anything else.

Here’s the updated configuration and automations yaml files:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Ossy
  # Location required to calculate the time the sun rises and sets
  latitude: !secret
  longitude: !secret
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 0
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/London
  # Customization file
  customize: !include customize.yaml

# 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

# Discover some devices automatically
discovery:

# Sensors
sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'time_date'
      - 'time_utc'
      - 'beat'
  # Weather prediction
  - platform: yr


# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

#Entity Variables

#Hot water timer inputs
input_datetime:
  hws_mo:
    name: Set time for water heater (Monday)
    has_date: false
    has_time: true

  hws_tu:
    name: Set time for water heater (Tuesday)
    has_date: false
    has_time: true

    hws_we:
    name: Set time for water heater (Wednesday)
    has_date: false
    has_time: true

  hws_th:
    name: Set time for water heater (Thursday)
    has_date: false
    has_time: true

  hws_fr:
    name: Set time for water heater (Friday)
    has_date: false
    has_time: true

  hws_sa:
    name: Set time for water heater (Saturday)
    has_date: false
    has_time: true

  hws_su:
    name: Set time for water heater (Sunday)
    has_date: false
    has_time: true

input_boolean:
  hws_enable:
    name: Hot water switch enable
    initial: off

- id: '1571092941517'
  alias: Hot Water On - One Hour
  description: Switches the water on for 1 hour at any time
  trigger:
  - entity_id: input_boolean.hws_enable
    platform: state
    to: 'on'
  condition: []
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - data:
      message: automation triggered  - Hot Water On - One Hour
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off
- id: '1577119893046'
  alias: 'DEBUG: Hot water switch on'
  description: ''
  trigger:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    platform: device
    type: turned_on
  condition: []
  action:
  - data:
      message: water heater on
    service: system_log.write
- id: '1577120792510'
  alias: 'DEBUG: Hot water switch off'
  description: ''
  trigger:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    platform: device
    type: turned_off
  condition: []
  action:
  - data:
      message: water heater off
    service: system_log.write
- id: '1577124991290'
  alias: Hot water - Monday
  description: Monday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_mo.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
   - mon
  action:
  - data:
      entity_id: automation.hot_water_on_one_hour
    service: automation.trigger
  - data:
      message: Monday automation triggered
    service: notify.notify

Any other thoughts?
Thanks again!
D

there’s way too much going on here with automations calling other automations and multple messages but nothing is standing out as to the 'problem.

my suggestion is to take it one step at a time. Start simple with just the basic automation and a simple trigger and get it working reliably then add more complexity.

If you don’t want automation with a trigger just put the automation actions in a script and call that script.

Hey folks, thanks for your input - sorry for the radio silence, the festive seasons put me out a bit and I didn’t get chance to look at this again until just now.

You’re right! Early optimisation is the root of all evil - so as suggested, I got rid of it. Unfortunately, I’m still having some issues.

I have removed the 1 hour water automation and the boolean that was used to make it work. Instead, there are now 7 separate automations, each dealing with a separate day of the week and each having the same on-notify-delay-off action.

Here are the automation and configuration files:

- id: '1577119893046'
  alias: 'DEBUG: Hot water switch on'
  description: ''
  trigger:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    platform: device
    type: turned_on
  condition: []
  action:
  - data:
      message: water heater on
    service: system_log.write
- id: '1577120792510'
  alias: 'DEBUG: Hot water switch off'
  description: ''
  trigger:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    platform: device
    type: turned_off
  condition: []
  action:
  - data:
      message: water heater off
    service: system_log.write
- id: '1577124991290'
  alias: 01 Hot Water - Monday
  description: Monday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_mo.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - mon
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - data:
      message: Monday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off
- id: '1577914049877'
  alias: 02 Hot Water - Tuesday
  description: Tuesday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_tu.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - tue
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - data:
      message: Tuesday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off
- id: '1577914184091'
  alias: 03 Hot Water - Wednesday
  description: Wednesday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_we.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - wed
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - data:
      message: Wednesday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off
- id: '1577914540313'
  alias: 04 Hot Water - Thursday
  description: Thursday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_th.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - thu
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - data:
      message: Thursday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off
- id: '1577914579041'
  alias: 05 Hot Water - Friday
  description: Friday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_fr.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - fri
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - data:
      message: Friday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off
- id: '1577914620437'
  alias: 06 Hot Water - Saturday
  description: Saturday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_sa.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - sat
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - data:
      message: Saturday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off
- id: '1577914651280'
  alias: 07 Hot Water - Sunday
  description: Sunday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_mo.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - sun
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - data:
      message: Sunday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off
homeassistant:
  # Name of the location where Home Assistant is running
  name: Ossy
  # Location required to calculate the time the sun rises and sets
  latitude: !secret
  longitude: !secret
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 0
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/London
  # Customization file
  customize: !include customize.yaml

# 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

# Discover some devices automatically
discovery:

# Sensors
sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'time_date'
      - 'time_utc'
      - 'beat'
  # Weather prediction
  - platform: yr


# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

#Entity Variables

#Hot water timer inputs
input_datetime:
  hws_mo:
    name: Set time for water heater (Monday)
    has_date: false
    has_time: true

  hws_tu:
    name: Set time for water heater (Tuesday)
    has_date: false
    has_time: true

  hws_we:
    name: Set time for water heater (Wednesday)
    has_date: false
    has_time: true

  hws_th:
    name: Set time for water heater (Thursday)
    has_date: false
    has_time: true

  hws_fr:
    name: Set time for water heater (Friday)
    has_date: false
    has_time: true

  hws_sa:
    name: Set time for water heater (Saturday)
    has_date: false
    has_time: true

  hws_su:
    name: Set time for water heater (Sunday)
    has_date: false
    has_time: true

Simple so far - I got it up and running with one automation and once I was happy that it was all working I made copies of the working automation and changed the day.

I did a bunch of testing yesterday evening:

weds test

This screenshot from the log shows the automation firing and in turn switching on the hot water switch. Notifications also arrived on my phone.

At 10:19 I switched the output switch off manually and at 10:20 the automation successfully switched the water off after 1 minute (instead of 1 hour).

This morning, however, things are looking less good:

thursfail

As you can see, the automation fired, but the switch didn’t actually turn on; the next log entries are unrelated events. Further, going and looking in Lovelace and in the cupboard; the switch was not on.

My questions remain the same then:

  • Is there something wrong with the way I’ve got this setup?
  • How can I make sure that things come on and off reliably?

Thanks again for your help,
Best,
D

OK, so just to be sure…

the wednesday automation completely correct? But the thursday one didn’t do anything in the actions at all? not even the notification portion?

If that’s correct then look in the home-assistant.log file (located in your config directory) for errors around the time that the thursday automation triggered. There may be something in there that said why the action failed.

Hi finity,

The Wednesday automation completed in its entirety, correct.

The Thursday automation sent a notification to my phone but didn’t do anything else.

Here’s everything in the log file:


2020-01-01 22:34:02 WARNING (MainThread) [homeassistant.components.script] Script script.1577910479630 already running.

2020-01-01 22:55:55 WARNING (MainThread) [homeassistant.components.websocket_api.http.connection.140504173968272] Disconnected: Did not receive auth message within 10 seconds

2020-01-02 02:13:17 WARNING (Thread-3) [pychromecast.socket_client] [Office Speaker:8009] Heartbeat timeout, resetting connection

2020-01-02 04:20:50 WARNING (Thread-6) [pychromecast.socket_client] [55OLED803/12:8009] Heartbeat timeout, resetting connection

2020-01-02 04:21:05 ERROR (Thread-6) [pychromecast.socket_client] [55OLED803/12:8009] Failed to connect to service TPM171E-150a8cc33a6393e5c4d44c8a2202f998._googlecast._tcp.local., retrying in 5.0s

2020-01-02 04:22:55 ERROR (Thread-4) [pychromecast.socket_client] [All:42956] Error reading from socket.

2020-01-02 04:22:55 WARNING (Thread-4) [pychromecast.socket_client] [All:42956] Error communicating with socket, resetting connection

2020-01-02 04:23:20 WARNING (Thread-2) [pychromecast.socket_client] [Living Room Speaker:8009] Heartbeat timeout, resetting connection

2020-01-02 04:23:44 ERROR (Thread-4) [pychromecast.socket_client] [All:42956] Error reading from socket.

2020-01-02 04:23:44 WARNING (Thread-4) [pychromecast.socket_client] [All:42956] Error communicating with socket, resetting connection

2020-01-02 04:25:11 WARNING (Thread-6) [pychromecast.socket_client] [55OLED803/12:8009] Heartbeat timeout, resetting connection

2020-01-02 04:30:57 WARNING (Thread-6) [pychromecast.socket_client] [55OLED803/12:8009] Heartbeat timeout, resetting connection

2020-01-02 04:31:27 ERROR (Thread-6) [pychromecast.socket_client] [55OLED803/12:8009] Failed to connect to service TPM171E-150a8cc33a6393e5c4d44c8a2202f998._googlecast._tcp.local., retrying in 5.0s

2020-01-02 06:06:01 WARNING (Thread-6) [pychromecast.socket_client] [55OLED803/12:8009] Heartbeat timeout, resetting connection

2020-01-02 06:06:31 ERROR (Thread-6) [pychromecast.socket_client] [55OLED803/12:8009] Failed to connect to service TPM171E-150a8cc33a6393e5c4d44c8a2202f998._googlecast._tcp.local., retrying in 5.0s

There are errors from last night that look like they are related to the script I was playing with but there’s nothing in there, after around 11pm when I stopped working on this.

All the errors after that are related to HA trying to talk to my TV/Google home.

So, if there’s no error and because I got a notification, I would presume that the automation fired but the actual call to the switch device didn’t work for some reason. I have no way of telling at the moment ‘where in the stack’ this fell over (e.g. was it a Z-WAVE issue or something inside HA?)

Is it possible to have conditionals/loops inside an automation or script that isn’t super breaky? My current line of thinking would be to:

  1. Fire automation to activate the switch
  2. Wait for time n
  3. Check and see if it is actually on
  4. If yes - do nothing and exit
  5. If no - re-issue device switch on command - GOTO 2

While this is somewhat treating the symptom and not the cause I am not sure how to proceed.

Thanks again for your help,

Best,

D

yes, that’s correct.

you could try to look in the OZW_log.txt file to see if there is anything in there around the time that the automation triggered that would indicate an error with the switch itself or the network in general.

I’m no zwave expert (or even HA for that matter :wink: ) so I’m not sure I could help with the interpretation of the log tho.

But it does sound like it might be a zwave issue since all of the automations are functionally the same and the notification worked indicating the automation did trigger correctly and that there is no error in the home-assistant.log file related to the automation.

as far as looping, I’m not sure I would set it so that you are in an infinite loop in case the valve never turns on. But you could run thru the turn_on service a few times just to see if it might work after a couple of tries.

you can do that by just calling the same service over again but put a normal condition directly in the action section that checks for the state of the switch.

like:

action:
  - service: service
    entity_id: entity
  - condition: state
    entity_id: entity
    state: 'off'
  - service: same_service
    entity_id: same_entity

then you can do that a few times you can even put debug info in there and add a service after the conditions that notifies you of how many times it tried before success or that it failed completely.

OK great thanks! That’s a good approach, infinite loops are not a thing we want.

I checked the log and it only goes back as far as yesterday so I can’t see what was happening when it failed last (which was Thursday, it worked fine on Friday and Saturday).

I’m not sure I quite follow you for putting a condition inside the action and calling the service again.

At the moment the automations look like this:

- id: '1577124991290'
  alias: 01 Hot Water - Monday
  description: Monday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_mo.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - mon
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - data:
      message: Monday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off

Repeating the on service a few times might look like this (including a 5 second delay between calls to the switch on command to prevent the network getting clogged up):

- id: '1577124991290'
  alias: 01 Hot Water - Monday
  description: Monday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_mo.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - mon
  action:
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - delay: 00:00:05
   - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - delay: 00:00:05
   - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_on
  - delay: 00:00:05
  - data:
      message: Monday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off

Applying your template to my application might look like this:

- id: '1577124991290'
  alias: 01 Hot Water - Monday
  description: Monday day condition is in config.yaml you can't see it here
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (states.input_datetime.hws_mo.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  condition:
  - after: 00:00:01
    before: '23:59:59'
    condition: time
    weekday:
    - mon
  action:
  - service: switch.turn_on
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
  - condition: state
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    state: 'off'
  - service: switch.turn_on
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
  - data:
      message: Monday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off

Is that right? I guess a few of the condition and service call lines could be added to get it to check a few times.

Just wanted to check I’m barking up the right tree before I sink a load of time into fiddling.

Thanks again!
D

that’s close but you need to put everything you want to usually happen before the condition (like the notification) because if the switch actually turns on then the condition won’t be satisfied and the rest of the action steps after the condition won’t be performed.

and you don’t need the device_id in the automation for a regular service call.

action:
  - service: switch.turn_on
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
  - data:
      message: Monday automation triggered
    service: notify.notify
  - delay: 01:00:00
  - condition: state
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    state: 'off'
  - service: switch.turn_on
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
  - data:
      message: valve didn't turn on. triggering attempt 2
    service: notify.notify
  - delay: 01:00:00
  - condition: state
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    state: 'off'
  - service: switch.turn_on
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
  - data:
      message: valve didn't turn on. triggering attempt 3
    service: notify.notify
  - delay: 01:00:00
  - condition: state
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    state: 'off'
  - data:
      message: valve hasn't turned on. aborting...
    service: notify.notify

That way it will try to turn the valve on three times and if it does turn on during any of those attempts the automation stops. If the valve never opens (or re-closes during the one minute delay) the automation stops and you will get a warning that the valve never opened. I think that would useful for debugging.

That’s awesome, I’ll give that a go this evening and see what happens.

For reference, the automations have been working OK until this morning again (tuesday) - I got the notification but the switch didn’t come on.

I checked the Zwave log again but it only has entries from the last hour or so which means everything from this morning is missing. I will either have to trigger a failed switch event and look in the log, wait for it to fail naturally and check right away or get logging to last for longer than an hour at a time.

I did some digging but I can’t find any obvious settings for the length/size of the Zwave log, any ideas where I might be able to change that?

In the meantime, I’ll update the automations based on your example, thanks for sorting out my syntax and so on, much appreciated. I do have some questions about it though. All the delays in the automation are for 1 hour if I’m reading it right, should it be more like this:

action:
  - service: switch.turn_on
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
  - data:
      message: Monday automation triggered
    service: notify.notify
  - delay: 00:01:00
  - condition: state
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    state: 'off'
  - service: switch.turn_on
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
  - data:
      message: valve didn't turn on. triggering attempt 2
    service: notify.notify
  - delay: 00:01:00
  - condition: state
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    state: 'off'
  - service: switch.turn_on
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
  - data:
      message: valve didn't turn on. triggering attempt 3
    service: notify.notify
  - delay: 00:01:00
  - condition: state
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    state: 'off'
  - data:
      message: valve hasn't turned on. aborting...
    service: notify.notify
  - delay: 01:00:00
  - device_id: 75fb2ec189524b3c81012dde9cbe066c
    domain: switch
    entity_id: switch.horstmann_secure_meters_sir321_rf_countdown_timer_switch
    type: turn_off

I think this will wait a minute between attempts (instead of an hour) and then wait an hour and action the switch off regardless of what happens (which is fine, if it was on then we want it to be off after an hour and if it stayed off then it doesn’t matter).

Does that look right to you?

Best,
D