How to create automations when using Fibaro Door/Window Sensor 2

Here are some findings, that may helps others…

After integrating up my new Fibaro Door/Window Sensor 2 via MQTT, I wondered why I failed to do automations with it.

For the quick ones, for door open/close, you get a value 22/23 and not a binary state AND whatever you do, at least at the moment, querying these values from that device never succeeds in automations.

Here is the procedure to make automations run :grinning:

  • If not already done or present, go to your configuration.yaml and create the following entry right next to the similar ones:
    template: !include templates.yaml
  • Then create a file if not exists named templates.yaml on the same level as the other includes.
  • Add the following to this (new) file, replace sensor.xxx with the one how you have it and set the name according your needs:
# collected templates
# device_class: door: on (true, 22) means open, off (false, 23) means closed

- binary_sensor:
    - name: Terrassentuer
      state: >
        {{ is_state_attr('sensor.wohnzimmer_terrassentuer_notification_access_control_door_state', 'value', 22) }}
      device_class: door
      icon: >
        {% if is_state_attr('sensor.wohnzimmer_terrassentuer_notification_access_control_door_state', 'value', 22) %}
          mdi:door-open
        {% else %}
          mdi:door-closed
        {% endif %}
  • If you have more of these sensors, just add more - name blocks.
  • Restart HA
  • Add a new automation and add two new trigger states, both referencing the new entity (name). For the first one set the to state to open leaving from empty and set a delay (eg 8s, if required), while for the second one you set close with 3s. The trigger will now run on any state change.
  • For playing around, you may want to first set a service action and add log with just a dummy text to see if it works. See the HA logbook for changes. You can simply disable that action later on.
  • Then, add a condition to actions and use the formerly created new entity from the template (name). Based on what you want to achieve, select one state (open/close) and a task what should happen. In my case it was to temporarily disable a thermostate, using the else condition to get it back.
  • Set an automation mode, I used restart
  • Give it a try and open-close the door.

Quite easy - if you know how …