Hello,
I’m trying to fade a light when I press and hold a button but I can’t get it to work.
This is my configuration:
Light:
light:
- platform: mqtt
schema: json
name: mqtt_json_light_1
state_topic: "home/ESP_LED_ESPEJO"
command_topic: "home/ESP_LED_ESPEJO/set"
brightness: true
effect: true
effect_list: [flash]
optimistic: false
qos: 0
Sensor:
- platform: mqtt
state_topic: "wemos/pulsacionlarga"
name: "touch_espejo_larga"
payload_on: "LONG_ON"
payload_off: "LONG_OFF"
Script:
fade_the_light:
Alias: Kitchen Brightness Decrease Button
sequence:
- service: light.turn_on
entity_id: light.mqtt_json_light_1
data_template:
transition: '1'
brightness_pct:>
{% set n = states.light.mqtt_json_light_1.attributes.brightness + 5%}
{% if n> 100%}
100
{% else%}
{{n}}
{% endif%}
Automation:
- id: '1623086575946'
alias: Fade luz espejo
description: ''
trigger:
- platform: state
entity_id: binary_sensor.touch_espejo_larga
from: 'off'
to: 'on'
condition: []
action:
- service: script.turn_on
target:
entity_id: script.fade_the_light
mode: single
If I try the data template in the templates section, it tells me the following:
UndefinedError: ‘mappingproxy object’ has no attribute 'brightness’
greetings