############################################################################### # PACKAGE: OpenHASP Lounge 1 Wall Plate Backlight Control # NODE/TOPIC ROOT: hasp/openhasp_1/ # # INTENT: # - Keep backlight control separate from the thermostat/heater UI package. # - Avoid using brightness 0 as the main OFF method. # - Wake the panel with "idle off" before applying brightness. # # OPENHASP NOTES: # - backlight brightness range is 1..255 # - backlight off is a state, not a brightness level # - idle off clears idle/sleep state and behaves like a wake-up ############################################################################### ############################################################################### # HELPERS ############################################################################### input_boolean: openhasp_1_backlight_enable: name: OpenHASP 1 Backlight Enable icon: mdi:television-ambient-light initial: true input_number: openhasp_1_backlight_level: name: OpenHASP 1 Backlight Level min: 1 max: 255 step: 1 mode: slider initial: 255 ############################################################################### # AUTOMATIONS ############################################################################### automation: # ------------------------------------------------------------------------- # Backlight enable helper changed # - ON -> wake panel and apply current brightness level # - OFF -> tell openHASP to switch the backlight off # ------------------------------------------------------------------------- - id: openhasp_1_backlight_enable_changed alias: "OpenHASP 1: backlight enable changed" mode: restart trigger: - platform: state entity_id: input_boolean.openhasp_1_backlight_enable action: - choose: - conditions: - condition: state entity_id: input_boolean.openhasp_1_backlight_enable state: "on" sequence: - service: script.openhasp_1_backlight_apply default: - service: script.openhasp_1_backlight_off # ------------------------------------------------------------------------- # Backlight level helper changed # - If backlight is enabled, apply the new level immediately # - If disabled, just store the new level for next time # ------------------------------------------------------------------------- - id: openhasp_1_backlight_level_changed alias: "OpenHASP 1: backlight level changed" mode: restart trigger: - platform: state entity_id: input_number.openhasp_1_backlight_level condition: - condition: state entity_id: input_boolean.openhasp_1_backlight_enable state: "on" action: - service: script.openhasp_1_backlight_apply # ------------------------------------------------------------------------- # Re-apply requested backlight state when Home Assistant starts # ------------------------------------------------------------------------- - id: openhasp_1_backlight_on_ha_start alias: "OpenHASP 1: apply backlight on HA start" mode: queued trigger: - platform: homeassistant event: start action: - delay: "00:00:10" - service: script.openhasp_1_backlight_apply_requested_state # ------------------------------------------------------------------------- # Re-apply requested backlight state when the panel reconnects # ------------------------------------------------------------------------- - id: openhasp_1_backlight_on_panel_online alias: "OpenHASP 1: apply backlight on panel online" mode: queued trigger: - platform: mqtt topic: "hasp/openhasp_1/LWT" condition: - condition: template value_template: "{{ trigger.payload == 'online' }}" action: - delay: "00:00:05" - service: script.openhasp_1_backlight_apply_requested_state # ------------------------------------------------------------------------- # If openHASP enters idle while HA says the backlight should be enabled, # wake it and re-apply the requested brightness. # # This is intended to stop the "black until touched" behaviour when the # plate's own idle state has blanked the display. # ------------------------------------------------------------------------- - id: openhasp_1_backlight_recover_from_idle alias: "OpenHASP 1: recover backlight from idle" mode: restart trigger: - platform: mqtt topic: "hasp/openhasp_1/state/idle" condition: - condition: state entity_id: input_boolean.openhasp_1_backlight_enable state: "on" - condition: template value_template: "{{ trigger.payload | lower != 'off' }}" action: - delay: "00:00:01" - service: script.openhasp_1_backlight_apply ############################################################################### # SCRIPTS ############################################################################### script: # ------------------------------------------------------------------------- # Apply current requested brightness. # # Important: # - Send idle off first so the panel is awake. # - Then send a JSON backlight command with state ON and brightness 1..255. # ------------------------------------------------------------------------- openhasp_1_backlight_apply: alias: "OpenHASP 1: apply backlight level" mode: restart sequence: - service: mqtt.publish data: topic: "hasp/openhasp_1/command" payload: "idle off" - delay: "00:00:00.25" - service: mqtt.publish data: topic: "hasp/openhasp_1/command" payload: > backlight {"state":"on","brightness":{{ states('input_number.openhasp_1_backlight_level') | int(255) }}} # Send once more shortly after. This helps with panels that miss the # brightness change while coming out of idle. - delay: "00:00:00.75" - service: mqtt.publish data: topic: "hasp/openhasp_1/command" payload: > backlight {"state":"on","brightness":{{ states('input_number.openhasp_1_backlight_level') | int(255) }}} # ------------------------------------------------------------------------- # Turn the backlight off using the openHASP backlight OFF state. # Do not set brightness to 0. # ------------------------------------------------------------------------- openhasp_1_backlight_off: alias: "OpenHASP 1: backlight off" mode: restart sequence: - service: mqtt.publish data: topic: "hasp/openhasp_1/command" payload: "backlight off" # ------------------------------------------------------------------------- # Apply either ON/current-level or OFF according to helper state. # Used on HA startup and panel reconnect. # ------------------------------------------------------------------------- openhasp_1_backlight_apply_requested_state: alias: "OpenHASP 1: apply requested backlight state" mode: restart sequence: - choose: - conditions: - condition: state entity_id: input_boolean.openhasp_1_backlight_enable state: "on" sequence: - service: script.openhasp_1_backlight_apply default: - service: script.openhasp_1_backlight_off