ratgdo / mqtt-ratgdo

ratgdo via mqtt
GNU General Public License v2.0
76 stars 16 forks source link

motion is detected but never clear & messes up light #41

Closed sejgit closed 6 months ago

sejgit commented 6 months ago

you likely know this one and are working on it but I just figured out (v2.56) that motion is detecting and updating mqtt it just never clears. related, when you walk into garage and motion turns the light on, it ends up making mqtt the opposite of reality. ie. off=on

joshjohanning commented 6 months ago

cc #36

I think that's reflected as a todo in the readme:

  • [ ] Flip light status on when motion detected packet is sent
sejgit commented 6 months ago

got it. thanks for all you are doing!

Goose66 commented 5 months ago

I think that's reflected as a todo in the readme:

  • [ ] Flip light status on when motion detected packet is sent

That TODO appears to be for updating light status on motion detected. This issue is related to the fact that the motion status is never reset to "clear." Going through the code, while the internal motion flag itself is set to clear (0) each time through the status loop (and several other places), there are not times when setting the motion flag to 0 results in a "clear" MQTT message being published. A message is only published when the motion flag is set to 1 ("detected"). What's more, it is published as a retained message, so the status in the MQTT broker will always return "detected" if it is queried or on new subscriptions, whether there is motion or not.

IMO, it should be either 1) managed like the other statuses with a previousMotionState and clear and detected messages posted each time it changes, or 2) should not be retained message with "detected" messages published only when motion is detected (and thus we would never expect a "clear" status).