Mysensors update entity on presentation

Hello,
I have HA in docker on my rpi4. I decided to use mysensor integration to receive events that button has been pressed. The information is going to the gateway and translated to mqtt.
My configuration of integration:

mysensors:
  gateways:
    - device: mqtt
      topic_in_prefix: "mygateway1-out"
      topic_out_prefix: "mygateway1-in"
      persistence_file: "mysensorsMQTT1.json"
  version: "2.3"
  retain: false

I have added automation to turn light on when there was a single click.

- alias: 'Klikniecie w wlacznik zapala swiatlo w schowku'
  trigger:
    platform: state
    entity_id: sensor.wallbuttons_14_4
  condition:
    condition: numeric_state
    entity_id: sensor.wallbuttons_14_4
    below: 2
  action:
    - service: light.toggle
      data:
        entity_id: light.schowek
        transition: 0

Everything works great, but when there is a power break or when I just restart the devices working on mysensors network, the automation is automaticaly triggered…

After logs check the reason was that devices were conducting presentation procedure again and presentation of the button triggered entity update (which triggered automation).

home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [mysensors.gateway_mqtt] Receiving 14;0;0;0;25;
home-assistant   | 2021-04-15 16:47:58 WARNING (MainThread) [mysensors.sensor] child_id 0 already exists in children of node 14, cannot add child
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [mysensors.gateway_mqtt] Receiving 14;4;0;0;25;
home-assistant   | 2021-04-15 16:47:58 WARNING (MainThread) [mysensors.sensor] child_id 4 already exists in children of node 14, cannot add child
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [mysensors.gateway_mqtt] Receiving 14;9;0;0;4;
home-assistant   | 2021-04-15 16:47:58 WARNING (MainThread) [mysensors.sensor] child_id 9 already exists in children of node 14, cannot add child
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [mysensors.gateway_mqtt] Receiving 14;5;0;0;4;
home-assistant   | 2021-04-15 16:47:58 WARNING (MainThread) [mysensors.sensor] child_id 5 already exists in children of node 14, cannot add child
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [mysensors.gateway_mqtt] Receiving 14;44;0;0;6;
home-assistant   | 2021-04-15 16:47:58 WARNING (MainThread) [mysensors.sensor] child_id 44 already exists in children of node 14, cannot add child
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [mysensors.gateway_mqtt] Receiving 14;55;0;0;7;
home-assistant   | 2021-04-15 16:47:58 WARNING (MainThread) [mysensors.sensor] child_id 55 already exists in children of node 14, cannot add child
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [mysensors.gateway_mqtt] Receiving 14;0;1;0;24;275
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 14 child 0
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [mysensors.gateway_mqtt] Receiving 14;0;2;0;24;
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [mysensors.gateway_mqtt] Publishing 14;0;1;0;24;275
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 9: value_type 3, value = 100
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 9: value_type 2, value = 1
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 9: value_type 24, value = 700
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 9: value_type 25, value = 300
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 9: value_type 26, value = 200
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 9: value_type 27, value = 1500
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 9: value_type 28, value = 0
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 5: value_type 3, value = 100
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 5: value_type 2, value = 0
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 5: value_type 24, value = 700
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 5: value_type 25, value = 300
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 5: value_type 26, value = 200
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 5: value_type 27, value = 1500
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 5: value_type 28, value = 0
home-assistant   | 2021-04-15 16:47:58 DEBUG (MainThread) [homeassistant.components.mysensors.device] Entity update: WallButtons 14 4: value_type 19, value = 1
home-assistant   | 2021-04-15 16:47:58 INFO (MainThread) [homeassistant.components.automation.klikniecie_w_wlacznik_zapala_swiatlo_w_schowku] Klikniecie w wlacznik zapala swiatlo w schowku: Running automation actions
home-assistant   | 2021-04-15 16:47:58 INFO (MainThread) [homeassistant.components.automation.klikniecie_w_wlacznik_zapala_swiatlo_w_schowku] Klikniecie w wlacznik zapala swiatlo w schowku: Executing step call service

Should the integration update the entity based on presentation message even the entity exists?
How can I overcome the problem?

Best regards,
Mariusz

Hey,

I’ve found workaround for it. When entire bus had reset, all devices are going presentation procedure including message with mysensors version protocol. I block automations for that period of time.

Just create new mqtt sensor:

sensor:
  - platform: mqtt
    state_topic: "mygateway1-out/14/255/0/0/17"
    name: "Wallbuttons version"
    force_update: true

and in every automation I add new condition

- condition: template
  value_template: >
    {{ (as_timestamp(now()) - as_timestamp(states.sensor.wallbuttons_version.last_changed)) > 20 }}

Best regards,
Mariusz