Setting dimmer brightness using an entity's attribute

Hi everyone,

I’ve started adding automations in my HA setup only a few days ago.

One automation I am trying to achieve is to link a sensor attribute (called door_sensor_3_8 (don’t bother with understanding the name really) with attribute V_PERCENTAGE from a MySensor node) to the dimmer level of a zwave Fibaro Dimmer.
The goal is to have the dimmer using the new value from the MySensor node every time the latter changes.

This is what I have :

- action:
  - alias: turn ligth brightness
    data_template:
      brightness_pct: '{{ states.sensor.door_sensor_3_8.attributes.V_PERCENTAGE |
        int }}'
      entity_id: light.fibaro_system_fgd212_dimmer_2_level
    service: light.turn_on
  alias: Change brightness
  condition: []
  id: '1505324256813'
  trigger:
  - above: '0'
    entity_id: sensor.door_sensor_3_8
    platform: numeric_state
    value_template: '{{ state.attributes.V_PERCENTAGE | int }}'

The action seems to work as I can execute the automation manually from HA web interface and the brightness of the zwave dimmer is updated.

The problem seems to be with the trigger part, which sometimes executes but more often not.

Do you have any idea about where the problem might come from ?

Thanks

I’m guessing this will only trigger if the value crosses your threshold. From below 0 to above 0. Going from 1 to 2 won’t re-trigger like you would want. Otherwise it would be triggered every second that it’s not 0, and probably spam your zwave network.

You could do it using appdaemon since you can subscribe to a state change, and you get the old and new values.

Or I would suggest running in on a time based automation and update every 5 minutes or something.

Use a template trigger instead:

Thank you both for you answerrs.

Would it be possible to just re,ove the threshold in the trigger ? The value of the percentage attribute is only changes when I press a button so I should not get spammed there if it is possible.

I’m going to check appdaemon, it seems very interesting especially for someone who already knows programming.

As for automation trigger I saw this chapter but I am not sure exactly how to make the trigger happen on each change of that specific attribute value that I’m interested in. Most of the examples seems to check for state to be equal or compared to a specific value. Here I would like to call the service for every change of the attribute state value.

Something like this:

trigger:
  platform: template
  entity_id: sensor.door_sensor_3_8
  value_template: '{% if states.sensor.door_sensor_3_8.attributes.V_PERCENTAGE | int > 0 %}true{% endif %}'

I get an error in the config file when I use your example.

Removing the entity_id line seemed to fix the issue.

  trigger:
    platform: template
    value_template: "{% if states.sensor.door_sensor_3_8.attributes.V_PERCENTAGE | int > 0 %}true{% endif %}"

The problem is that I end up with exactly the same behavior as with the numeri_state : the service if only called if I first change the value to 0 and then to another value.
I tried removing the >0 but that did not change a thing.

I might have to setup appdaemon in the end…

Sorry - I was looking for something else and came across this.
Is this still awaiting a solution ?
if you create a input_number scaled as your v_percentage sensor then trigger when the two don’t match (not equivalent)
the resultant action would be to set_value on the slider to the trigger_to value and then also write that to your light, re-scaling if your light requires 255 as max (so *2.55 assuming your sensor is 0-100)
AND the above assumes that you can’t just use ‘state’ as a trigger on your sensor change, normally state works for me.
regards
Mutt