renemarc/home-assistant-config

View on GitHub
automations/devices/kiosk_auto.yaml

Summary

Maintainability
Test Coverage
#
# Toggle kiosk display
#
# Max brightness is capped at 25% of 256, otherwise the power supply cannot cope
# with the constant-on backlight power needs of an Acer Iconia One 10. Even with
# a quality 2.4 amps charger, which is weird.
#
# @subscribe input_boolean.night_mode
#
- id: kiosk_auto
  alias: "Kiosk AUTO"

  trigger:
    # When night mode is changed.
    - platform: state
      entity_id: input_boolean.night_mode

  action:
    # Dim/brighten display.
    - service: shell_command.kiosk_brightness
      data:
        host: !secret fully_kiosk_host
        port: !secret fully_kiosk_port
        password: !secret fully_kiosk_password
      data_template:
        value: >-
          {% if is_state('input_boolean.night_mode', 'off') %}
            64
          {% else %}
            0
          {% endif %}

    # Keep the screen on for a few more seconds when we're turning it off.
    - delay: >-
        {% if is_state('input_boolean.night_mode', 'off') %}
          00:00:00
        {% else %}
          00:00:05
        {% endif %}

    # Toggle display.
    - service_template: >-
        {% if is_state('input_boolean.night_mode', 'off') %}
          homeassistant.turn_on
        {% else %}
          homeassistant.turn_off
        {% endif %}
      entity_id: display.kiosk