Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lights turn on after restart of zigbee2mqtt - workaround? #992

Closed
h4nc opened this issue Feb 1, 2019 · 16 comments
Closed

Lights turn on after restart of zigbee2mqtt - workaround? #992

h4nc opened this issue Feb 1, 2019 · 16 comments

Comments

@h4nc
Copy link

h4nc commented Feb 1, 2019

I have a xiaomi double switch that turns on my lights.

After a restart zigbee2mqqt publishes all the states again and so my automation in homeassistant gets triggered and turns on my lights.

Is there a way to bypass this? May turning of publishing the events at restart for certain devices?

My automation looks like this:

- alias: Zigbee Doppelschalter - left
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id: sensor.zigbee_doppelschalter_click
  condition:
    - condition: state
      entity_id: sensor.zigbee_doppelschalter_click
      state: 'left'          
  action:
    - service: light.turn_on
      entity_id: light.licht

My config in zigbee looks like this:

  '0xXXX':
    friendly_name: Zigbee Doppelschalter
    retain: false
@Koenkk
Copy link
Owner

Koenkk commented Feb 1, 2019

Probably a duplicate of #959

@h4nc
Copy link
Author

h4nc commented Feb 1, 2019

I don't know if this really is the same issue. As my problem is pushing the states (probably saved in state.json) at the start of zigbee2mqtt causes this.

I also have the same issue with my ikea tradfri dimmer. If I turn of my light with alexa, the dimmer value will still be let's say "150". After a restart this will turn on the light.

This only would be a workarround but I could imagine two solutions:

  • zigbee2mqtt side: don't publish the state of the device at the beginning, or clear the state before (for certain devices = push buttons)
  • home assistant side: ignore zigbee2mqtt for X seconds after startup, don't know how or if thats possible. This would cause other issues, like door sensors not beeing updated.

Mind that this also could be a security issue.
For instance if you want to trigger a garage door to open by a push button a restart of zigbee (caused by a power failure) would open the garage door.

EDIT:
another idea: maybe it is possible to add an information to the pushed mqtt topic. We could use this information for a condition in ha. This information should contain if zigbee just started or it is a real trigger.

@Koenkk
Copy link
Owner

Koenkk commented Feb 2, 2019

Stop when home assistant is not running, do you also experience this?

@h4nc
Copy link
Author

h4nc commented Feb 2, 2019

I don't understand. When home assistant does not run, there is no automation to be triggered, so in this case no lights will turn on.
Or do you ask if the "start messaged" appear in zigbee2mqtt

@Koenkk
Copy link
Owner

Koenkk commented Feb 2, 2019

When using the automation format from the wiki, does this also happen (https://koenkk.github.io/zigbee2mqtt/integration/home_assistant.html - Responding to button clicks)

@h4nc
Copy link
Author

h4nc commented Feb 2, 2019

Looks like this works. The reason is that those three values are reportet at the start up:

{"battery":100,"voltage":3035,"linkquality":42}

click is not included, so the automation is not triggered.

So restarting zigbee doesn't trigger that anymore.

To be totaly sure I still have to test if a ha or a mosquitto restart will trigger this.
Maybe at the start up of mosquitto it fired those messages again. I don't know that. Do you?

EDIT: I just found out the following: So responding to button clicks will work for the aqara buttons (click is not reportet in the mqtt message at start up of zigbee2mqtt).
The ikea dimmer does report its brightness value at startup. So this one will be triggered.

{"brightness":233,"linkquality":15,"last_seen":"2019-01-20T14:33:06.418Z","battery":87}

This might be an issue for other devices too. It depends on wch data they report at startup. I guess the coord pings those devices at startup??? and than gets those values, right? The device "decides" which information it sends.

@Koenkk
Copy link
Owner

Koenkk commented Feb 2, 2019

No that shouldn't be the case.

Let me know if this can be closed.

@h4nc
Copy link
Author

h4nc commented Feb 2, 2019

I edited my comment above. This will still be an issue for devices like the ikea dimmer.

@Koenkk
Copy link
Owner

Koenkk commented Feb 2, 2019

The brightness of the Tradfri dimmer is something added by zigbee2mqtt. Stateless attributes like ('click', 'action') shouldn't be reported, but stateful (like brightness) should be.

What is the problem that this will be triggered?

@h4nc
Copy link
Author

h4nc commented Feb 2, 2019

Because this trigger will turn on lights with the reported brightness value.

If you turn off a light (not with the dimmer) and than restart zigbee2mqtt the brightness value will trun on that light again.

Edit: Also I jsut found out that a restart of home assistant triggers that automation? do I have to change something at the retain setting?

this automation is triggered at start up, don't know why. There is another mqtt message after the restart, but it doesn't contain "click", so I can't explain my self why this gets triggers. And even more weird, the "right" side doesn't get triggered (even if I press the right button before, so it has that state saved).

- alias: Zigbee doubleswitch - left
  initial_state: 'on'
  trigger:
    platform: mqtt
    topic: 'zigbee2mqtt/Zigbee doubleswitch'
  condition:
    condition: template
    value_template: '{{ "left" == trigger.payload_json.click }}'        
  action:
    - service: light.toggle
      entity_id: light.licht
    - service: notify.ios_iphone
      data:
        message: "left triggered"  

@Koenkk
Copy link
Owner

Koenkk commented Feb 2, 2019

@h4nc
Copy link
Author

h4nc commented Feb 2, 2019

So there is no issue with the dimmer, if you only use the dimmer to control a light.

If you use other ways too: voice control, ha UI
than the state of the dimmer will cause issues.

However could you explain a little more what I should do in that code?

Edit: I don’t think I can change that code as I don’t know how to this in the hassio addon. But if you change that I can pull the update and try it out.

Also I tried restarting home assistant and mosquito. The left button gets triggered. I think it has something to do with the retain state. But it looks like the left one is the to retain true and the right one to false (as this one doesn’t get triggered).
In the configuration I have it set to retain: false.

@h4nc
Copy link
Author

h4nc commented Feb 2, 2019

I don’t know why but it looks like the retain flag was set to true, so mosquito published the information at the restart.
Do you have an explanation why the retain flag went to true?
Just asking, because I’d like to know if this could happen again.

To get rid of this I deleted my mosquito addon and reinstalled it.
Thus probably isn’t the smartest way to do that. But I knew this would delete the database. Is there another way to do this in future?

@Koenkk
Copy link
Owner

Koenkk commented Feb 3, 2019

@h4nc retain flag is set manually in configuration.yaml. A retained MQTT messages can be cleared by sending a message to the same topic without the retain flag.

@h4nc
Copy link
Author

h4nc commented Feb 3, 2019

Thanks for clearing that. To still it will be easier to delete and reinstall to clear the database, as finding the right topic and publish.

I still don’t get why my left button was retain: true.

I‘m thinking about using one of those Aqara sensors to trigger a security sensitive automation.
But before I do this I must be a 100% sure the automation is only triggered when I push the button. And not from a restart of similar things.

@Koenkk
Copy link
Owner

Koenkk commented Feb 3, 2019

@h4nc agree! We are trying find the correct automation in #959. For now, the MQTT trigger can be used.

@Koenkk Koenkk closed this as completed Feb 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants