I am setting up some android tablets to run WallPanel app. It allows me to change its brightness via MQTT and that works great. Here’s the requirement:
When sun is up/bright, the wall panel should be on BRIGHT (e.g. 200/255 or more)
When sun is low, the brightness should be controlled by the room’s light group e.g. light.living).
In other words, when its sunny it should be bright, in evening/night, the light should dim with the living room’s light group entity, thus it won’t be glaring too brightly.
I do not think I can use the value of a light entity as an input trigger, and the light has several ways of being controlled by remote or voice command.
It also needs to adjust automatically when the sun changes.
How can I setup a given command (e.g. MQTT publish) to respond on change of either light.living (light group entity) or the sun entity. The current value of both would need to be usable in my action.
Sorry I left the most important part off (updated):
How can I setup a given command (e.g. MQTT publish) to respond on change of either light.living (light group entity) or the sun entity. The current valueof both would need to be usable in my action.
I’ve figured out how to do what I want.
The WallPanel tablet will be its configured maximum brightness during the day (as the ambient light or sunshine is bright).
During night, it will scale the light proportionately to the room’s light up to the configured maximum. When the light is off, the tablet is at its minimum so it doesn’t glare during the night.
alias: WallPanelBrightness
description: ""
trigger:
- platform: state
entity_id: light.office
attribute: brightness
- platform: state
entity_id: sun.sun
attribute: elevation
condition: []
action:
- service: mqtt.publish
data_template:
topic: wallpanel/living/command
payload: >
# Define the max value we want the wall panel brightness, of possible 255.
{% set light_max = 200 %}
# Important to ensure we don't query the entity brightness attribute if its None
{% if state_attr('light.office','brightness') == None %}
{% set light_float = 0.0 %}
{% else %}
{% set light_float = float(state_attr('light.office','brightness'))/255.0 %}
{% endif %}
{% if states.sun.sun.attributes.elevation >= 0 %}
# During day-time, use the max value for wallpanel
{"brightness": {{light_max}} }
{% else %}
# During night-time, scale the wallpanel proportionately to the light
{"brightness": {{ max(light_max * light_float,1) }} }
{% endif %}
mode: single
Next will be a kind of template or blueprint, so I can handle multiple rooms.