renemarc/home-assistant-config

View on GitHub
misc/binary_sensors.yaml

Summary

Maintainability
Test Coverage
#
# Binary sensors
#
# @link https://www.home-assistant.io/integrations/binary_sensor/
#


#
# Flic smart button
#
# This points to the local flicd daemon that handles the actual Flic buttons.
#
# @link https://flic.io/
# @link https://github.com/renemarc/resin-flic
# @link https://www.home-assistant.io/integrations/flic/
#
- platform: flic
  host: !secret flic_host
  port: !secret flic_port
  discovery: true
  timeout: 3


#
# Fully Kiosk Browser motion sensor
#
# The Fully app can only send "onMotion" events as it is stateless. Instead of
# coming up with a complicated yet fragile Javascript state-handler that would
# calculate the last time any motion was detected and then send an "off" signal
# and would survive across URL changes (but would fail if the Android device is
# offline or if the app is forced-closed), an extra server-side sensor is much
# sturdier, if a bit less accurate. It should turn off within 3-4 minutes after
# the last change.
#
# The "binary_sensor.kiosk_motion" is dynamically created by the first
# "onMotion" event call for a custom Javascript declared in all dashboards using
# the "Modern" theme. Two API calls are done sequentially, one to turn off the
# binary sensor, then other to turn it right  back on. This way the sensor state
# is guaranteed to change, and the  "last_changed" and "last_updated" timestamps
# along with it.
#
# @see /appdaemon/custom_css/modern/variables.yaml
#
- platform: template
  sensors:
    kiosk_motion_auto:
      friendly_name: "Kiosk Motion"
      device_class: motion
      entity_id:
        - sensor.time
        - binary_sensor.kiosk_motion
      delay_off:
        seconds: 5
      value_template: >-
        {{ is_state('binary_sensor.kiosk_motion', 'on')
           and (180 >= as_timestamp(now()) - as_timestamp(states.binary_sensor.kiosk_motion.last_changed)) }}


#
# FireFighter Siren Monitor smoke alarm sensor
#
# The Ecolink FireFighter Z-Wave Plus for Smoke and CO Detectors does have a
# binary sensor exposed by the Z-Wave management console, but it does not relate
# to smoke or burglar ...and the unit has no configuration options exposed.
#
# The siren monitor returns 0x02 for both smoke and CO detection, or 0x00 when
# no such events are triggered.
#
# There are no garage, fireplace or any other fuel burning equipment here, and
# so there are no CO detectors that need to be listened to either.
#
# @link https://discoverecolink.com/product/firefighter-wireless-smoke-co-audio-sensor/
#
- platform: template
  sensors:
    siren_monitor_smoke:
      friendly_name: "Smoke Detector"
      device_class: smoke
      entity_id:
        - sensor.siren_monitor_smoke
      value_template: >-
        {{ is_state('sensor.siren_monitor_smoke', '2') }}


#
# Motion sensors
#
- platform: template
  sensors:
    motion_front:
      friendly_name: "Front Motion"
      device_class: motion
      entity_id:
        - input_boolean.motion_front
      value_template: >-
        {{ is_state('input_boolean.motion_front', 'on') }}


#
# Device online/presence status
#
- platform: template
  sensors:
    laptop_her:
      friendly_name: "Her Laptop"
      device_class: presence
      icon_template: "mdi:laptop"
      value_template: >-
        {% set laptop_her = is_state('device_tracker.laptop_her', 'home') %}

        {{ laptop_her }}

    laptop_him:
      friendly_name: "His Laptop"
      device_class: presence
      icon_template: "mdi:laptop"
      value_template: >-
        {% set laptop_him = is_state('device_tracker.laptop_him', 'home') %}
        {% set laptop_him_bt = is_state('device_tracker.laptop_him_bt', 'home') %}
        {% set laptop_him_ethernet = is_state('device_tracker.laptop_him_ethernet', 'home') %}

        {{ laptop_him or laptop_him_bt or laptop_him_ethernet }}

    kiosk_status:
      friendly_name: "Kiosk"
      device_class: connectivity
      icon_template: "mdi:tablet"
      value_template: >-
        {% set kiosk = is_state('device_tracker.kiosk', 'home') %}
        {% set kiosk_ping = is_state('device_tracker.kiosk_ping', 'home') %}

        {{ kiosk or kiosk_ping }}