Strange behaviour

Hi All,

I have 2 Neo Coolcam Door sensors and 2 Fibaro Door Sensors.

All 4 show correct value when open:

sensor.fibaro_imac_custom_sensor > on
sensor.fibaro_frontdoor_custom_sensor > on
binary_sensor.node_21 > on
binary_sensor.node_12 > on

Only the Fibaro binary_sensors show: Door/Window Closed (Using Zwave2Mqtt)
So created the 2 sensors to change this in on and off

###########################################################################################
#
# SENSOR TEMPLATE
#
# https://www.home-assistant.io/integrations/template/
#
###########################################################################################
---
platform: template
sensors:
  fibaro_imac_custom_sensor:
    friendly_name: "Fibaro iMac"
    value_template: "{{ 'on' if is_state('sensor.node_13_access_control', 'Door/Window Open') else 'off' }}"
    icon_template: "{{ 'mdi:checkbox-blank-circle-outline' if is_state('sensor.node_13_access_control', 'Door/Window Open') else 'mdi:check-circle' }}"

  fibaro_frontdoor_custom_sensor:
    friendly_name: "Fibaro Frontdoor"
    value_template: "{{ 'on' if is_state('sensor.node_11_access_control', 'Door/Window Open') else 'off' }}"
    icon_template: "{{ 'mdi:checkbox-blank-circle-outline' if is_state('sensor.node_11_access_control', 'Door/Window Open') else 'mdi:check-circle' }}"

When I try this code in developer tool:

{% if states('sensor.fibaro_imac_custom_sensor') == 'off' %} open
{% else %} closed
{% endif %}

This is part of the code, was trying. Actual Automation will be this:

###########################################################################################
#
# NOTIFY WHEN DOORS OPEN OR CLOSE
#
###########################################################################################

- alias: "Notification - Random Door Open Close"
  trigger:

    platform: state
    entity_id:
      - binary_sensor.node_21 # Sensor Diningroom Door
      - binary_sensor.node_12 # Sensor Bedroom Door
      - sensor.fibaro_frontdoor_custom_sensor
      - sensor.fibaro_imac_custom_sensor

  action:
    service: script.pushover_engine
    data_template:
      message: >-
        {% if trigger.to_state.state == 'on' %}
          {{ trigger.from_state.attributes.friendly_name}} is open
        {% else %}
          {{ trigger.from_state.attributes.friendly_name}} is closed
        {% endif %}
      priority: "0"
      sound: "bike"
      title: "HA Notify Engine"

The binary_sensors shown correct output, but the sensor. show reverted valueā€¦
I canā€™t find it where it goes wrongā€¦ Can someone help me out?

Nothing strange, your logic is reversed.

Here you say if the door is off, itā€™s open.

{% if states('sensor.fibaro_imac_custom_sensor') == 'off' %} open

Here you say if the door is on, itā€™s open.

        {% if trigger.to_state.state == 'on' %}
          {{ trigger.from_state.attributes.friendly_name}} is open

also, for what itā€™s worth you can simply this and get everything into the binary_sensor domain

Put this in binary_sensor, not sensor. Youā€™ll get different icons, they will be square instead of circles.

binary_sensor

platform: template
sensors:
  fibaro_imac_custom_sensor:
    friendly_name: "Fibaro iMac"
    value_template: "{{ is_state('sensor.node_13_access_control', 'Door/Window Open') }}"
    device_class: opening

  fibaro_frontdoor_custom_sensor:
    friendly_name: "Fibaro Frontdoor"
    value_template: "{{ is_state('sensor.node_11_access_control', 'Door/Window Open') }}"
    device_class: opening

check

{{ 'open' if is_state('binary_sensor.fibaro_imac_custom_sensor', 'on') else 'closed' }}

automation

- alias: "Notification - Random Door Open Close"
  trigger:
  - platform: state
    entity_id:
      - binary_sensor.node_21 # Sensor Diningroom Door
      - binary_sensor.node_12 # Sensor Bedroom Door
      - binary_sensor.fibaro_frontdoor_custom_sensor
      - binary_sensor.fibaro_imac_custom_sensor
  action:
    service: script.pushover_engine
    data_template:
      message: >-
        {{ trigger.from_state.attributes.friendly_name }} is {{ 'open' if trigger.to_state.state == 'on' else 'closed' }}
      priority: "0"
      sound: "bike"
      title: "HA Notify Engine"
1 Like

Thanks for all the info, maybe I did some mess up in the code I posted here. But this seems to work :slight_smile: so Iā€™m learning every day :slight_smile:

Hi @petro,

Here again. I did a check

{{ 'open' if is_state('binary_sensor.fibaro_imac_custom_sensor', 'on') else 'closed' }

On these sensors:

binary_sensor.node_21
binary_sensor.node_12
binary_sensor.fibaro_frontdoor_custom_sensor
binary_sensor.fibaro_imac_custom_sensor

They all show the correct value. When open template shows open. Butā€¦

- alias: "Notification - Random Door Open Close"
  trigger:
  - platform: state
    entity_id:
      - binary_sensor.node_21 # Sensor Diningroom Door
      - binary_sensor.node_12 # Sensor Bedroom Door
      - binary_sensor.fibaro_frontdoor_custom_sensor
      - binary_sensor.fibaro_imac_custom_sensor
  action:
    service: script.pushover_engine
    data_template:
      message: >-
        {{ trigger.from_state.attributes.friendly_name }} is {{ 'open' if trigger.to_state.state == 'on' else 'closed' }}
      priority: "0"
      sound: "bike"
      title: "HA Notify Engine"

Now revert result. The Fibaro sensors show correct values. But Neo Coolcam show reverted value.
When open it sends closed, when close it sends open.

I can change the value of Fibaro in Zwave2MQTT. Revert the open.close value. When open it shows close, when close it shows open. Then its corrected. But its strange when the value of all sensors show correct In development template.
:slight_smile:

I have no idea what youā€™re saying. All i can say is that your automation is correct. It will send you a message when the door opens and when the door closes. If you do a quick open and close, the last message will always be close and the second to last will be open.

I split-up the 2 different sensors now in 2 different automations.

Change the line for NeoCoolcam Sensor into:

{ trigger.from_state.attributes.friendly_name }} is {{ 'open' if trigger.to_state.state == 'off' else 'closed' }}

And for the Fibaro Sensors into:

{ trigger.from_state.attributes.friendly_name }} is {{ 'open' if trigger.to_state.state == 'on' else 'closed' }}

Otherwise it wonā€™t work. But when I do the test:

{{ 'open' if is_state('binary_sensor.fibaro_imac_custom_sensor', 'on') else 'closed' }}

Alll 4 sensors give the same valueā€¦

show me using the template editor all 4 entities

And Please correct the formatting on Post #4
Edit: Sorry, this is a quote from petro, and it always messes up ā€˜quotesā€™

Also note that your title does not conform to guidelines ā€˜Strange behaviourā€™ of what ? This is not helpful.

Fibaro iMac Door

{{ 'open' if is_state('binary_sensor.fibaro_imac_custom_sensor', 'on') else 'closed' }}

Output: open

State: on

friendly_name: Fibaro iMac
device_class: door
templates: 
icon: 'mdi:leak'
icon_color: 'if (state === ''on'') return ''rgba(251,214,67,1)''; return ''rgba(71,116,157,1)'';'
icon: mdi:leak
icon_color: rgba(251,214,67,1)

Fibaro Frontdoor

{{ 'open' if is_state('binary_sensor.fibaro_frontdoor_custom_sensor', 'on') else 'closed' }}

Output: closed

State: off

friendly_name: Fibaro Frontdoor
device_class: door
templates: 
icon: 'mdi:leak'
icon_color: 'if (state === ''on'') return ''rgba(251,214,67,1)''; return ''rgba(71,116,157,1)'';'

icon: mdi:leak
icon_color: rgba(71,116,157,1)

NeoCoolcam Diningroom

{{ 'open' if is_state('binary_sensor.node_21', 'on') else 'closed' }}

Output: open

State: on

value_id: 83-48-1-0
node_id: 83
class_id: 48
type: bool
genre: user
instance: 1
index: 0
label: Sensor
units: 
help: Binary Sensor State
read_only: true
write_only: false
min: 0
max: 0
is_polled: false
value: true
lastUpdate: 1588862927637
friendly_name: Diningroom Door
device_class: door
icon: mdi:leak

NeoCoolcam Bedroom

{{ 'open' if is_state('binary_sensor.node_12', 'on') else 'closed' }}

Output: closed

State: off

value_id: 82-48-1-0
node_id: 82
class_id: 48
type: bool
genre: user
instance: 1
index: 0
label: Sensor
units: 
help: Binary Sensor State
read_only: true
write_only: false
min: 0
max: 0
is_polled: false
value: false
lastUpdate: 1588847335792
friendly_name: Bedroom Door
device_class: door
icon: mdi:leak

Not sure what to tell you that I already havenā€™t. Verify that you arenā€™t getting multiple notifications and your notification system is only showing you the last notification.

Everything looks correct. And test it with a long delay before I close the doors.
Refresh the pushover app to see latest notify before I close it again and see the next notify.

I really donā€™t understand thisā€¦ but split them up and change 1 automation with other if statement, it work. Not the cleanest solution haha.

@petro I had a clear moment. I changed from ZWave in HA to Zwave2mqtt. Add all nodes without knowing there was a known problem in Z2M. Correct that but didnā€™t removed the 2 Neo Coolcam sensors and add them again.

Now add them correct and everything is solvedā€¦