Automation for non-dimmable lamps on dimmers

A while ago I started replacing some CFL and occasion incandescent lamps with LED bulbs. Later, I installed a bunch of Z-Wave dimmer modules, and have the occasional problem where the humans in the house managed to “dim” the lamps when operating the dimmer switch on the wall manually, rather than turning the lamps all the way off.

So I put together an automation to detect and fix this problem. This works pretty well. When the light changes state (usually from off to on), if the brightness is not full (255), then we turn the lamp to full brightness.

Note that in the trigger condition, the “to:” bit is commented out. So the automation will act on any state change, not just a transition from “off” to “on”. This is handy as it will catch the case where the light is dimmed from the state card (or some other HASS mechanism) while it is already on, and the brightness will be reset to 255.

The one use-case where this isn’t working for me is when the light is on, and then manually dimmed (but not turned off). The changed brightness isn’t provoking a state change. I do have HASS polling the Z-Wave switch and it does detect when the light is turned off. I’m not sure if this is a bug in the light switch, or a feature in HASS where a changed dimmer level isn’t reported as a state change.

In practice around here, what happens is that the light gets dimmed very low (but not off), or dimmed and then turned off. When next turned back on, the state change is noticed, and the brightness level restored to full (255).

- alias: dimmers to full brightness
  initial_state: true
  trigger:
    platform: state
    # if you enable the to: condition, then you'll miss changes in brightness made
    # when lamp is already on.  this only happens when changing brightness in hass
    #to: 'on'
    entity_id:
      - light.lab_level
      - light.kitchen_inside_level
      - light.kitchen_center_level
      - light.kitchen_outside_level
      - light.parlor_level
      - light.upstairs_office_level
      - light.upstairs_hall_level
      - light.blue_bedroom_level
      - light.master_bedroom_level
      - light.upstairs_steps_level
      - light.attic_level

  condition:
    condition: template
    value_template: '{{ (trigger.to_state is not none) and (trigger.to_state.state == "on") and
             (trigger.to_state.attributes is not none) and ((trigger.to_state.attributes["brightness"] | int) < 255) }}'
  action:
    - service: logbook.log
      data_template:
        name: "Z-Wave partial brightness"
        message: '{{trigger.entity_id}} was at brightness {{trigger.to_state.attributes["brightness"]}}'
        entity_id: '{{ trigger.entity_id }}'

    - service: light.turn_on
      data_template:
        entity_id: "{{ trigger.entity_id }}"
        brightness: 255
2 Likes

IIRC you can set whether a lamp is dimmable or not in the Zwave settings.

The primary problem I’m trying to solve is when someone manually operating the switch on the wall manages to dim the lights while just trying to turn them off. I took a look, but didn’t see a way to set an attribute in the GE/Jasco dimmers that I have to disable the dimming function…

I’m not an expert here, but maybe you could try using attribute based sensor (based on dimmer brightness). Such sensor will report the actual brightness as its state, hence changes to brightness should provoke state change of such sensor.

But when will the template sensor based on the attributes get updated… usually, that’s on a state change of the entity and I’m not sure if that triggering happens if the attribute changes state. In practice, the current solution “works” and it doesn’t require me to individually configure a bunch of extra sensor entities as I add more z-wave dimmer devices.