Sometimes light is skipped with automation

I have a raspberry pi 3 with an aeotec zwave stick. Sometimes when automations run, a random light will be skipped. I can see all of the devices seem to have a good connection from the zwave integration, I also installed an aeotec zwave repeater in the middle of our house to be safe. Would anyone know why this would happen?

The main reason I want to use home assistant, is to auto turn on lights at sunset, and then dim them later after sunset. If someone overrides a light brightness on the physical switch, then the automation that follows shouldn’t stomp on what they have set. Here is one sample automation that runs 30 mins after sunset. (below). I have 2 more that run later in the evening after this:

alias: Light - Night(+30) - Medium Brightness
description: ''
trigger:
  - platform: sun
    event: sunset
    offset: '+00:30:00'
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.main_bedroom', 'on') and
              state_attr('light.main_bedroom', 'brightness') | int > 120 and
              state_attr('light.main_bedroom', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.main_bedroom
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.claire_room', 'on') and
              state_attr('light.claire_room', 'brightness') | int > 120 and
              state_attr('light.claire_room', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.claire_room
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.paul_room', 'on') and
              state_attr('light.paul_room', 'brightness') | int > 120 and
              state_attr('light.paul_room', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.paul_room
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.downstairs_bedroom', 'on') and
              state_attr('light.downstairs_bedroom', 'brightness') | int > 120
              and state_attr('light.downstairs_bedroom', 'brightness') | int <
              135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.downstairs_bedroom
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.upstairs_bathroom', 'on') and
              state_attr('light.upstairs_bathroom', 'brightness') | int > 120 and
              state_attr('light.upstairs_bathroom', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.upstairs_bathroom
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.upstairs_shower', 'on') and
              state_attr('light.upstairs_shower', 'brightness') | int > 120 and
              state_attr('light.upstairs_shower', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.upstairs_shower
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.downstairs_bathroom', 'on') and
              state_attr('light.downstairs_bathroom', 'brightness') | int > 120
              and state_attr('light.downstairs_bathroom', 'brightness') | int <
              135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.downstairs_bathroom
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.kitchen_pots', 'on') and
              state_attr('light.kitchen_pots', 'brightness') | int > 120  and
              state_attr('light.kitchen_pots', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.kitchen_pots
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.pots', 'on') and state_attr('light.pots',
              'brightness') | int > 120  and state_attr('light.pots',
              'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.pots
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.front_door', 'on') and
              state_attr('light.front_door', 'brightness') | int > 120  and
              state_attr('light.front_door', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.front_door
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.pendants', 'on') and
              state_attr('light.pendants', 'brightness') | int > 120 and
              state_attr('light.pendants', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.pendants
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.upstairs_living_room', 'on') and
              state_attr('light.upstairs_living_room', 'brightness') | int > 120 
              and state_attr('light.upstairs_living_room', 'brightness') | int <
              135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.upstairs_living_room
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.table', 'on') and state_attr('light.table',
              'brightness') | int > 120  and state_attr('light.table',
              'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.table
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.under_cabinet', 'on') and
              state_attr('light.under_cabinet', 'brightness') | int > 120  and
              state_attr('light.under_cabinet', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.under_cabinet
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.upstairs_hallway', 'on') and
              state_attr('light.upstairs_hallway', 'brightness') | int > 120 and
              state_attr('light.upstairs_hallway', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.upstairs_hallway
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.downstairs_hallway', 'on') and
              state_attr('light.downstairs_hallway', 'brightness') | int > 120 
              and state_attr('light.downstairs_hallway', 'brightness') | int <
              135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.downstairs_hallway
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.downstairs_hallway_2', 'on') and
              state_attr('light.downstairs_hallway_2', 'brightness') | int > 120 
              and state_attr('light.downstairs_hallway_2', 'brightness') | int <
              135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.downstairs_hallway_2
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.downstairs_living_room', 'on') and
              state_attr('light.downstairs_living_room', 'brightness') | int >
              120  and state_attr('light.downstairs_living_room', 'brightness') |
              int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.downstairs_living_room
    default: []
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ is_state('light.hue_white_lamp_1', 'on') and
              state_attr('light.hue_white_lamp_1', 'brightness') | int > 120  and
              state_attr('light.hue_white_lamp_1', 'brightness') | int < 135 }}
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 40
            target:
              entity_id: light.hue_white_lamp_1
    default: []
mode: single

Taking a look after, in the logs, I see a node that gets skipped, or doesn’t get it’s new brightness. I see this log but after this node’s brightness just stayed at its old Level which was 25 (not 50).:

2021-03-17 17:39:23.679 Detail, Node002, Refreshed Value: old value=255, new value=255, type=byte
2021-03-17 17:39:23.679 Detail, Node002, Changes to this value are not verified
2021-03-17 17:39:23.679 Detail, Node002, Notification: ValueChanged
2021-03-17 17:39:23.680 Info, Node002, Value::Set - COMMAND_CLASS_SWITCH_MULTILEVEL - Level - 0 - 1 - 50
2021-03-17 17:39:23.680 Info, Node002, SwitchMultilevel::Set - Setting to level 50
2021-03-17 17:39:23.680 Info, Node002,   Duration: Default
2021-03-17 17:39:23.680 Detail, Node002, Queuing (Send) SwitchMultilevelCmd_Set (Node=2): 0x01, 0x0b, 0x00, 0x13, 0x02, 0x04, 0x26, 0x01, 0x32, 0xff, 0x25, 0x2c, 0x02
2021-03-17 17:39:23.680 Detail, Node002, Queuing (Send) SwitchMultilevelCmd_Get (Node=2): 0x01, 0x09, 0x00, 0x13, 0x02, 0x02, 0x26, 0x02, 0x25, 0x2d, 0xc9

If I wait a couple minutes, re-run the same automation, the light gets it’s correct brightness set to 50. I looked through the logs, and it looks the same. The only difference I noticed is the RTT is lower.

Which Z-Wave integration are you using?

If you’re using the one that has been around for a while, have you set refresh_value & delay for these lights? (See Z-Wave Configuration Variables.)

Are just the brightness attributes of the light entities not changing to the correct values, or do the lights themselves actually not change to the correct brightness levels?

FWIW, your automation can be simplified quite a bit. E.g., here is one much more compact way to write it:

alias: Light - Night(+30) - Medium Brightness
description: ''
trigger:
  - platform: sun
    event: sunset
    offset: '+00:30:00'
variables:
  lights:
    - main_bedroom
    - claire_room
    - paul_room
    - downstairs_bedroom
    - upstairs_bathroom
    - upstairs_shower
    - downstairs_bathroom
    - kitchen_pots
    - pots
    - front_door
    - pendants
    - upstairs_living_room
    - table
    - under_cabinet
    - upstairs_hallway
    - downstairs_hallway
    - downstairs_hallway_2
    - downstairs_living_room
    - hue_white_lamp_1
condition: []
action:
  - repeat:
      count: "{{ lights | count }}"
      sequence:
        - variables:
            light: "light.{{ lights[repeat.index] }}"
        - choose:
            - conditions: >
                {{ is_state(light, 'on') and
                   120 < state_attr(light, 'brightness') < 135 }}
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: "{{ light }}"
                  data:
                    brightness_pct: 40

Assuming the other two automations are very similar, e.g., just with different brightness values, the actions could be broken out into a script with variables passed in, and then called from each of the three automations, passing in the appropriate values. Or, I suppose, it could be turned into a Blueprint, but I haven’t played with those yet so I couldn’t help there.

I’m not sure, but it might just be that the light attribute does not get changed to the correct value for one out of 19 lights. (I’m not sure maybe the light is actually changing brightness). I’ll have to test more.

I’m using the older Z-Wave one that now says deprecated. No. I have not set the refresh_value, or delay. Do you have any recommended settings for that? They are all inovelli red series dimmer switches.

This is awesome thank you. I was wondering if it is possible to loop through each light like this. I’ll test out your recommended template.

The delay value to use depends on the light; i.e., how long does it take to fully transition. E.g., I use GE Z-Wave dimmers, and by default they take around 3 seconds to transition. So I use a value of 4 seconds. Also, I have two of these dimmers – one is a newer Z-Wave Plus device, and the older one is not. So I use polling with the older one, but I disable polling for the Z-Wave Plus dimmer.

Here’s what I have in zwave_device_config.yaml for these two dimmers:

# Node 7
light.family_room_lamp:
  ignored: false
  polling_intensity: 1
  refresh_value: true
  delay: 4
# Node 9
light.master_bedroom_lamp:
  ignored: false
  polling_intensity: 0
  refresh_value: true
  delay: 4

The second one is the newer Z-Wave Plus dimmer.

Ok. Thank you. I’ll have to play around with this. Some of the lights we have have a bit of a transition time, like 1-3 seconds, and some don’t.

I think with the Inovelli switches it might be a bit different. There are a few settings that can be adjusted.

  • Dimming Speed (3)
  • Ramp Rate (Default 101)
  • Dimming Speed from Switch (Default 101)
  • Ramp Rate from Switch (Default 101)

So if I set Ramp Rate from Switch to 0, it basically tells the switch to instant power on/off the lightbulb. But if I set the “Ramp Rate” which is the zwave one to 0, for some reason it doesn’t seem to instant on and off the light. So i’ll probably just leave these as default for now.

FWIW, the GE/Jasco Z-Wave dimmers I use have similar parameters that can control how fast the light will turn on/off. But I’ve pretty much just left them at their default values.

Note that this “ramping” thing is a bit more complex than it might seem at first. One factor (at least for my GE dimmers) is whether or not a brightness is supplied when calling light.turn_on. If not, then the light ramps to the last “on” brightness it was commanded to. But if a brightness value is provided with the light.turn_on service call, then the light changes immediately to that level (i.e., the ramp parameters don’t apply.) Then there’s the light.turn_on service’s transition parameter. Not exactly sure how that works because I haven’t really used it.

Interesting. So after a bunch of testing. With the inovelli light switches, I finally found out why it wasn’t working well for me. The settings are not labelled correctly, parameters 1 and 3 are swapped. Found it documented here: https://community.inovelli.com/t/dimming-speed-and-ramp-rate-parameter1-and-parameter3-are-swapped/3529

So when I thought I was adjusting the ramp time, I was actually adjusting the dimming speed and vice versa, in turn throwing everything off in home assistant. It is working really well now. I’m about to test your refresh settings you suggested again now that this is fixed.

I’ve noticed when I turn the dimming speed to 0 in the switch firmware, the “transition” setting in home assistant doesn’t work well, but it seems to depend on the type of light fixture as well. Some light fixtures that I have that have a voltage controller in them are much smoother with dimming speeds, and transition. So ya, I’ve noticed I have to normally set the dimming parameter on the smart switch, and test it with that type of light fixture to see the transition.

For sending the brightness with the z-wave command, that is a good point you have. On the Inovelli switches they have an onboard memory, so these additional settings:

  • 9 - Default Level (Local) - Default level for the dimmer when it is powered on from the local switch. A setting of 0 means that the switch will return to the level that it was on before it was turned off.
  • 10 - Default Level (Z-Wave) - Default level for the dimmer when it is powered on from a Z-Wave command. A setting of 0 means that the switch will return to the level that it was on before it was turned off.

Depending on sun elevation/time of day. I’m setting these two parameters. I wonder if maybe I shouldn’t be setting the “Z-Wave” default level if home assistant sends the brightness with it when turning the light on. I guess I’ll have to check the command log to see what it does.

Thanks again for that template, it is working so much better, and way less code!

1 Like

@pnbruckner I tested with different settings. I put the zwave ramp time, and dimming speed to 0 on the inovelli switches, and then having the following setting:

light.main_bedroom:
ignored: false
polling_intensity: 0
refresh_value: false

It seems to have improved the switch toggle buttons in home assistant a lot. Now they toggle on and off quickly, and the toggle doesn’t flip back and forth waiting for a response.

So, the problem is still occurring when occasionally one light doesn’t respond. If I toggle all lights off for example, one light may randomly stay as showing on in home assistant, and is physically still on.

If I check one of the stats on these lights, I do see SentFailed numbers, and slow RTT times. I’m wondering if maybe it is just poor z-wave signal, and maybe I need to move my home assistant hub/aeotec stick, and my aeotec range extender 7 to a better location central in the house. Here is a screenshot on one device that just didn’t turn on and was missed:

I guess that’s possible. Also have you healed the network lately?

yup. I tried healing the network and no difference. I tried moving my HA hub, aeotec stick , and aeotec range extender 7 to a better location and it seems to make a big difference. So I think it’s def just z-wave latency. It seems like it doesn’t go through the floors/walls in our house very far. Surprising though, as our house is pretty small.