C19HOP / WiSafe2-to-HomeAssistant-Bridge

Connect FireAngel WiSafe2 alarm networks to HomeAssistant
50 stars 10 forks source link

Update Home Assistant configuration #6

Open ssillen opened 9 months ago

ssillen commented 9 months ago

I happily used your project, thank you for the hard work. However, I upgraded the sensors config according to the latest Home Assistant principles (2024.1). The availability of the sensors is also automatically updated, based on heartbeat & "missing" events. I'm using the /dev/serial/by-id/ as serial_port, because the /dev/ttyUSB can sometimes change when (un)plugging new devices or doing a restart. Hopefully this might be of use.

config.yaml:

tts:
  - platform: google_cloud
    base_url: http://192.168.0.200:8123
    key_file: googlecloud.json
    voice: en-GB-Wavenet-B
    encoding: linear16
    speed: 0.9
    pitch: -1.0

notify:
  - platform: group
    name: all_mobile_app_devices
    services:
      - service: mobile_app_iphone_1
      - service: mobile_app_iphone_2

recorder:
  exclude:
    entity_globs: 
      - sensor.fireangel_data   
      #Excludes the heartbeat updates from the radio (changes every few seconds)

#-----------------
#FireAngel Sensors
#-----------------
sensor:
  # FireAngel Gateway
  - platform: serial
    name: "FireAngel Data"
    serial_port: /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0
    baudrate: 115200

template:
  #-----------------
  #FireAngel Sensors
  #-----------------
  - binary_sensor:
      - name: "FireAngel Gateway Connectivity"
        unique_id: fireangel_heartbeat
        device_class: connectivity
        state: >
          {% if states('sensor.fireangel_data') !='unknown' and (now() - states.sensor.fireangel_data.last_changed).total_seconds() < 125 %}
            on
          {% else %}
            off
          {% endif %}

  - trigger:
      - platform: state
        entity_id: sensor.fireangel_data
      - platform: state
        entity_id: binary_sensor.fireangel_gateway_connectivity
    sensor:
      - name: "FireAngel Messages"
        unique_id: fireangel_messages
        icon: mdi:message-processing
        state: >
          {% if not '{' in states('sensor.fireangel_data') %}
            {{states('sensor.fireangel_data')}}
          {% endif %}
      - name: "FireAngel Built in Test Function"
        unique_id: fireangel_pseudo_firmware_alarm
        state: >
          {% if state_attr('sensor.fireangel_data', 'device')=='a5b813'.upper() %}
            {{ state_attr('sensor.fireangel_data', 'event') }}
          {% endif %}
    binary_sensor:
      - name: "FireAngel Radio"
        unique_id: fireangel_radio
        device_class: connectivity
        availability: "{{ states('binary_sensor.fireangel_gateway_connectivity') == 'on' }}"
        state: >
          {% if 'INIT OK' in states('sensor.fireangel_data') %}
            on
          {% elif 'Radio not ready - Trying to reset' in states('sensor.fireangel_data') or states('sensor.fireangel_data') == 'Initializing radio' %}
            off
          {% else %}
            {{this.state}}
          {% endif %}
      #------------------------------------
      #A76F18 | FP1720W2-R | Heat | Kitchen
      #------------------------------------
      - name: "FireAngel Heat Alarm Kitchen Connectivity"
        unique_id: fireangel_kitchen_connectivity
        device_class: connectivity
        availability: "{{ states('binary_sensor.fireangel_gateway_connectivity') == 'on' and states('binary_sensor.fireangel_radio') != 'off' }}"
        state: >
          {% if state_attr('sensor.fireangel_data', 'device')=='a76f18'.upper() %}
            {% if state_attr('sensor.fireangel_data', 'event')=='MISSING' %}
              off
            {% else %}
              on
            {% endif %}
          {% else %}
            {{this.state}}
          {% endif %}
      - name: "FireAngel Heat Alarm Kitchen Heat Status"
        unique_id: fireangel_kitchen_heat_status
        device_class: heat
        availability: "{{ states('binary_sensor.fireangel_heat_alarm_kitchen_connectivity') == 'on' }}"
        state: >
          {% if state_attr('sensor.fireangel_data', 'event')=='SILENCE' %}
            off
          {% elif state_attr('sensor.fireangel_data', 'device')=='a76f18'.upper() %}
            {% if state_attr('sensor.fireangel_data', 'event')=='FIRE EMERGENCY' %}
              on
            {% else %}
              {{this.state}}
            {% endif %}
          {% else %}
            {{this.state}}
          {% endif %}
      - name: "FireAngel Heat Alarm Kitchen CO Status"
        unique_id: fireangel_kitchen_co_status
        device_class: carbon_monoxide
        availability: "{{ states('binary_sensor.fireangel_heat_alarm_kitchen_connectivity') == 'on' }}"
        state: >
          {% if state_attr('sensor.fireangel_data', 'event')=='SILENCE' %}
            off
          {% elif state_attr('sensor.fireangel_data', 'device')=='a76f18'.upper() %}
            {% if state_attr('sensor.fireangel_data', 'event')=='CARBON MONOXIDE EMERGENCY' %}
              on
            {% else %}
              {{this.state}}
            {% endif %}
          {% else %}
            {{this.state}}
          {% endif %}
      - name: "FireAngel Heat Alarm Kitchen Heat Test"
        unique_id: fireangel_kitchen_heat_test
        device_class: problem
        icon: mdi:thermometer
        availability: "{{ states('binary_sensor.fireangel_heat_alarm_kitchen_connectivity') == 'on' }}"
        state: >
          {% if state_attr('sensor.fireangel_data', 'device')=='a76f18'.upper() %}
            {% if state_attr('sensor.fireangel_data', 'event')=='FIRE TEST' %}
              {% if state_attr('sensor.fireangel_data', 'result')=='PASS' %}
                off
              {% else %}
                on
              {% endif %}
            {% else %}
              {{this.state}}
            {% endif %}
          {% else %}
            {{this.state}}
          {% endif %}
      - name: "FireAngel Heat Alarm Kitchen CO Test"
        unique_id: fireangel_kitchen_co_test
        device_class: problem
        icon: mdi:molecule-co
        availability: "{{ states('binary_sensor.fireangel_heat_alarm_kitchen_connectivity') == 'on' }}"
        state: >
          {% if state_attr('sensor.fireangel_data', 'device')=='a76f18'.upper() %}
            {% if state_attr('sensor.fireangel_data', 'event')=='CARBON MONOXIDE TEST' %}
              {% if state_attr('sensor.fireangel_data', 'result')=='PASS' %}
                off
              {% else %}
                on
              {% endif %}
            {% else %}
              {{this.state}}
            {% endif %}
          {% else %}
            {{this.state}}
          {% endif %}
      - name: "FireAngel Heat Alarm Kitchen Battery"
        unique_id: fireangel_kitchen_battery
        device_class: battery
        availability: "{{ states('binary_sensor.fireangel_heat_alarm_kitchen_connectivity') == 'on' }}"
        state: >
          {% if state_attr('sensor.fireangel_data', 'device')=='a76f18'.upper() and states.sensor.fireangel_data.attributes.battery is defined %}
            {% if state_attr('sensor.fireangel_data', 'battery')=='LOW' %}
              on
            {% else %}
              off
            {% endif %}
          {% else %}
            {{this.state}}
          {% endif %}
      - name: "FireAngel Heat Alarm Kitchen On Base"
        unique_id: fireangel_kitchen_onbase
        device_class: presence
        availability: "{{ states('binary_sensor.fireangel_heat_alarm_kitchen_connectivity') == 'on' }}"
        state: >
          {% if state_attr('sensor.fireangel_data', 'device')=='a76f18'.upper() and states.sensor.fireangel_data.attributes.base is defined %}
            {% if state_attr('sensor.fireangel_data', 'base')=='OFF' %}
              off
            {% else %}
              on
            {% endif %}
          {% else %}
            {{this.state}}
          {% endif %}
    #------------------------------------
    #2D8D01 | FP2620W2 | Smoke | Bedroom
    #------------------------------------
    - name: "FireAngel Smoke Alarm Bedroom Connectivity"
      unique_id: fireangel_bedroom_connectivity
      device_class: connectivity
      availability: "{{ states('binary_sensor.fireangel_gateway_connectivity') == 'on' and states('binary_sensor.fireangel_radio') != 'off' }}"
      state: >
        {% if state_attr('sensor.fireangel_data', 'device')=='2d8d01'.upper() %}
          {% if state_attr('sensor.fireangel_data', 'event')=='MISSING' %}
            off
          {% else %}
            on
          {% endif %}
        {% else %}
          {{this.state}}
        {% endif %}
    - name: "FireAngel Smoke Alarm Bedroom Smoke Status"
      unique_id: fireangel_bedroom_smoke_status
      device_class: smoke
      availability: "{{ states('binary_sensor.fireangel_smoke_alarm_bedroom_connectivity') == 'on' }}"
      state: >
        {% if state_attr('sensor.fireangel_data', 'event')=='SILENCE' %}
          off
        {% elif state_attr('sensor.fireangel_data', 'device')=='2d8d01'.upper() %}
          {% if state_attr('sensor.fireangel_data', 'event')=='FIRE EMERGENCY' %}
            on
          {% else %}
            {{this.state}}
          {% endif %}
        {% else %}
          {{this.state}}
        {% endif %}
    - name: "FireAngel Smoke Alarm Bedroom CO Status"
      unique_id: fireangel_bedroom_co_status
      device_class: carbon_monoxide
      availability: "{{ states('binary_sensor.fireangel_smoke_alarm_bedroom_connectivity') == 'on' }}"
      state: >
        {% if state_attr('sensor.fireangel_data', 'event')=='SILENCE' %}
          off
        {% elif state_attr('sensor.fireangel_data', 'device')=='2d8d01'.upper() %}
          {% if state_attr('sensor.fireangel_data', 'event')=='CARBON MONOXIDE EMERGENCY' %}
            on
          {% else %}
            {{this.state}}
          {% endif %}
        {% else %}
          {{this.state}}
        {% endif %}
    - name: "FireAngel Smoke Alarm Bedroom Smoke Test"
      unique_id: fireangel_bedroom_smoke_test
      device_class: problem
      icon: mdi:thermometer
      availability: "{{ states('binary_sensor.fireangel_smoke_alarm_bedroom_connectivity') == 'on' }}"
      state: >
        {% if state_attr('sensor.fireangel_data', 'device')=='2d8d01'.upper() %}
          {% if state_attr('sensor.fireangel_data', 'event')=='FIRE TEST' %}
            {% if state_attr('sensor.fireangel_data', 'result')=='PASS' %}
              off
            {% else %}
              on
            {% endif %}
          {% else %}
            {{this.state}}
          {% endif %}
        {% else %}
          {{this.state}}
        {% endif %}
    - name: "FireAngel Smoke Alarm Bedroom CO Test"
      unique_id: fireangel_bedroom_co_test
      device_class: problem
      icon: mdi:molecule-co
      availability: "{{ states('binary_sensor.fireangel_smoke_alarm_bedroom_connectivity') == 'on' }}"
      state: >
        {% if state_attr('sensor.fireangel_data', 'device')=='2d8d01'.upper() %}
          {% if state_attr('sensor.fireangel_data', 'event')=='CARBON MONOXIDE TEST' %}
            {% if state_attr('sensor.fireangel_data', 'result')=='PASS' %}
              off
            {% else %}
              on
            {% endif %}
          {% else %}
            {{this.state}}
          {% endif %}
        {% else %}
          {{this.state}}
        {% endif %}
    - name: "FireAngel Smoke Alarm Bedroom Battery"
      unique_id: fireangel_bedroom_battery
      device_class: battery
      availability: "{{ states('binary_sensor.fireangel_smoke_alarm_bedroom_connectivity') == 'on' }}"
      state: >
        {% if state_attr('sensor.fireangel_data', 'device')=='2d8d01'.upper() and states.sensor.fireangel_data.attributes.battery is defined %}
          {% if state_attr('sensor.fireangel_data', 'battery')=='LOW' %}
            on
          {% else %}
            off
          {% endif %}
        {% else %}
          {{this.state}}
        {% endif %}
    - name: "FireAngel Smoke Alarm Bedroom On Base"
      unique_id: fireangel_bedroom_onbase
      device_class: presence
      availability: "{{ states('binary_sensor.fireangel_smoke_alarm_bedroom_connectivity') == 'on' }}"
      state: >
        {% if state_attr('sensor.fireangel_data', 'device')=='2d8d01'.upper() and states.sensor.fireangel_data.attributes.base is defined %}
          {% if state_attr('sensor.fireangel_data', 'base')=='OFF' %}
            off
          {% else %}
            on
          {% endif %}
        {% else %}
          {{this.state}}
        {% endif %}

#---------------------------------------------------------
#FireAngel shell commands (used to send data to the alarms)
#---------------------------------------------------------
shell_command:
   fireangel_test_co: /bin/bash -c "echo -e -n "1~" > /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0"
   fireangel_test_smoke: /bin/bash -c "echo -e -n "2~" > /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0"
   fireangel_test_all: /bin/bash -c "echo -e -n "3~" > /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0"
   fireangel_emergency_co: /bin/bash -c "echo -e -n "4~" > /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0"
   fireangel_emergency_smoke: /bin/bash -c "echo -e -n "5~" > /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0" 
   fireangel_silence_co: /bin/bash -c "echo -e -n "6~" > /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0"    
   fireangel_silence_smoke: /bin/bash -c "echo -e -n "7~" > /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0"    
   fireangel_get_pairing: /bin/bash -c "echo -e -n "8~" > /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0"
   fireangel_start_pairing: /bin/bash -c "echo -e -n "9~" > /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0"

lovelace.yaml:

views:
  - title: Home
    cards:
      - type: vertical-stack
        cards:
          - type: entities
            entities:
              - entity: binary_sensor.fireangel_gateway_connectivity
              - entity: binary_sensor.fireangel_radio
              - entity: sensor.fireangel_data
              - entity: sensor.fireangel_messages
            title: Gateway
          - square: true
            type: grid
            cards:
              - show_name: true
                show_icon: true
                type: button
                tap_action:
                  action: call-service
                  service: shell_command.fireangel_test_smoke
                  target: {}
                name: Test Fire
                icon: mdi:smoke
              - show_name: true
                show_icon: true
                type: button
                tap_action:
                  action: call-service
                  service: shell_command.fireangel_test_CO
                  target: {}
                name: Test CO
                icon: mdi:molecule-co
              - show_name: true
                show_icon: true
                type: button
                tap_action:
                  action: call-service
                  service: shell_command.fireangel_test_all
                  target: {}
                name: Test all
                icon: mdi:volume-high
              - show_name: true
                show_icon: true
                type: button
                tap_action:
                  action: call-service
                  service: shell_command.fireangel_emergency_smoke
                  target: {}
                icon: mdi:smoke
                name: Smoke alarm
              - show_name: true
                show_icon: true
                type: button
                tap_action:
                  action: call-service
                  service: shell_command.fireangel_emergency_co
                  target: {}
                name: CO-alarm
                icon: mdi:molecule-co
              - show_name: true
                show_icon: true
                type: button
                tap_action:
                  action: call-service
                  service: shell_command.fireangel_get_pairing
                  target: {}
                name: Check Radio Pairing
                icon: mdi:signal-variant
              - show_name: true
                show_icon: true
                type: button
                tap_action:
                  action: call-service
                  service: shell_command.fireangel_silence_smoke
                  target: {}
                name: Silence fire
                icon: mdi:smoke-detector-off
              - show_name: true
                show_icon: true
                type: button
                tap_action:
                  action: call-service
                  service: shell_command.fireangel_silence_co
                  target: {}
                name: Silence CO
                icon: mdi:smoke-detector-off-outline
              - show_name: true
                show_icon: true
                type: button
                tap_action:
                  action: call-service
                  service: shell_command.fireangel_start_pairing
                  target: {}
                name: Initiate Pairing
                icon: mdi:signal-distance-variant
            columns: 3
      - type: entities
        entities:
          - entity: binary_sensor.fireangel_heat_alarm_kitchen_heat_status
            name: Heat status
          - entity: binary_sensor.fireangel_heat_alarm_kitchen_co_status
            name: CO status
          - entity: binary_sensor.fireangel_heat_alarm_kitchen_battery
            name: Battery
          - entity: binary_sensor.fireangel_heat_alarm_kitchen_on_base
            name: On Base
          - entity: binary_sensor.fireangel_heat_alarm_kitchen_connectivity
            name: Connectivity
          - entity: binary_sensor.fireangel_heat_alarm_kitchen_heat_test
            name: Heat test
          - entity: binary_sensor.fireangel_heat_alarm_kitchen_co_test
            name: CO test
        title: Kitchen
      - type: entities
        entities:
          - entity: binary_sensor.fireangel_smoke_alarm_bedroom_smoke_status
            name: Rook status
          - entity: binary_sensor.fireangel_smoke_alarm_bedroom_co_status
            name: CO status
          - entity: binary_sensor.fireangel_smoke_alarm_bedroom_battery
            name: Battery
          - entity: binary_sensor.fireangel_smoke_alarm_bedroom_on_base
            name: On Base
          - entity: binary_sensor.fireangel_smoke_alarm_bedroom_connectivity
            name: Connectivity
          - entity: binary_sensor.fireangel_smoke_alarm_bedroom_smoke_test
            name: Rook test
          - entity: binary_sensor.fireangel_smoke_alarm_bedroom_co_test
            name: CO test
        title: Bedroom

I'm using node-red for automations, so I didn't update/test automations.yaml

NeoDuder commented 4 months ago

Hey,

Thanks for this, I've just updated my config and it looks a lot cleaner. I am, however having an issue with connectivity. Any ideas...

image

ssillen commented 4 months ago

Hey,

Thanks for this, I've just updated my config and it looks a lot cleaner. I am, however having an issue with connectivity. Any ideas...

image

You have to initialize the connectivity of all the smoke sensors to "on". The bridge needs a message from each smoke sensor to confirm it's connected, because it doesn't know the initial state. So you can trigger an event on each smoke sensor by triggering an alarm or removing the smoke sensor from the base. Or you can set the connectivity via the Developer Tools.

NeoDuder commented 4 months ago

Thanks for the reply. I have initiated a test, all alarms sound. I've removed all of the alarms from their base and refitted. No change in any of the statuses.

ssillen commented 4 months ago

Gateway connectivity and radio are ok, the connectivity sensor of each smoke sensor is available, so it would have to be in the configuration of the smoke sensor connectivity sensor. Please check the device id's in your configuration. Compare with the input you get from sensor.fireangel_data when triggering an event on your smoke sensor.

NeoDuder commented 4 months ago

Ok, so done some experimentation.

If I initiate a test from each alarm, the section for that alarm on my dashboard gets updated. I've now done that on all alarms, and all statuses are showing. However, if I initiate an alarm situation on any alarm, the statuses do not update. I held a lighter under my Kitchen Heat Sensor until it went off. All alarms sounded, "Fire Angel Data" on my dashboard showed the emergency message, but the status pages remain unchanged, with the kitchen still showing "Heat Status: Normal". Also, removing any alarm from it's base does not update the status.

EDIT

Ignore all of that. It appears that it just takes a little bit of time to update. Seems to be working now. :)

Thanks for the assistance :)