question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MQTT switches broken

See original GitHub issue

Describe the bug The MQTT switches are completely broken if the clips option for a camera is set to False. When starting Frigate, it sends the current state of the clips camera option to the topics clips/state, snapshots/state and detect/state. And since it also sets the retain flag, when restarting frigate everything backfires and sets clips, snapshots and detect to OFF since the handler also sets stuff when it arrives on the state topic.

mqtt.py:

    for name in config.cameras.keys():
        client.publish(f"{mqtt_config.topic_prefix}/{name}/clips/state", 'ON' if config.cameras[name].clips.enabled else 'OFF', retain=True)
        client.publish(f"{mqtt_config.topic_prefix}/{name}/snapshots/state", 'ON' if config.cameras[name].clips.enabled else 'OFF', retain=True)
        client.publish(f"{mqtt_config.topic_prefix}/{name}/detect/state", 'ON' if config.cameras[name].clips.enabled else 'OFF', retain=True)
def on_detect_command(client, userdata, message):
        payload = message.payload.decode()
        logger.debug(f"on_detect_toggle: {message.topic} {payload}")

        camera_name = message.topic.split('/')[-3]
        command = message.topic.split('/')[-1]

        detect_settings = config.cameras[camera_name].detect

        if payload == 'ON':
            if not camera_metrics[camera_name]["detection_enabled"].value:
                logger.info(f"Turning on detection for {camera_name} via mqtt")
                camera_metrics[camera_name]["detection_enabled"].value = True
                detect_settings._enabled = True
        elif payload == 'OFF':
            if camera_metrics[camera_name]["detection_enabled"].value:
                logger.info(f"Turning off detection for {camera_name} via mqtt")
                camera_metrics[camera_name]["detection_enabled"].value = False
                detect_settings._enabled = False
        else:
            logger.warning(f"Received unsupported value at {message.topic}: {payload}")

        if command == "set":
            state_topic = f"{message.topic[:-4]}/state"
            client.publish(state_topic, payload, retain=True)

Version of frigate 0.8.0 RC1

Logs

frigate.mqtt                   INFO    : MQTT connected
frigate.mqtt                   DEBUG   : on_clips_toggle: frigate/driveway/clips/state OFF
frigate.mqtt                   DEBUG   : on_clips_toggle: frigate/frontdoor/clips/state OFF
frigate.mqtt                   DEBUG   : on_clips_toggle: frigate/backyard/clips/state OFF
frigate.mqtt                   DEBUG   : on_snapshots_toggle: frigate/driveway/snapshots/state OFF
frigate.mqtt                   INFO    : Turning off snapshots for driveway via mqtt
frigate.mqtt                   DEBUG   : on_snapshots_toggle: frigate/frontdoor/snapshots/state OFF
frigate.mqtt                   INFO    : Turning off snapshots for frontdoor via mqtt
frigate.mqtt                   DEBUG   : on_snapshots_toggle: frigate/backyard/snapshots/state OFF
frigate.mqtt                   INFO    : Turning off snapshots for backyard via mqtt
frigate.mqtt                   DEBUG   : on_detect_toggle: frigate/driveway/detect/state OFF
frigate.mqtt                   INFO    : Turning off detection for driveway via mqtt
frigate.mqtt                   DEBUG   : on_detect_toggle: frigate/frontdoor/detect/state OFF
frigate.mqtt                   INFO    : Turning off detection for frontdoor via mqtt
frigate.mqtt                   DEBUG   : on_detect_toggle: frigate/backyard/detect/state OFF
frigate.mqtt                   INFO    : Turning off detection for backyard via mqtt
frigate.app                    INFO    : Camera processor started for backyard: 34
detector.cpu1                  INFO    : Starting detection process: 31
frigate.app                    INFO    : Camera processor started for frontdoor: 35
frigate.app                    INFO    : Camera processor started for driveway: 36
frigate.app                    INFO    : Capture process started for backyard: 37
frigate.app                    INFO    : Capture process started for frontdoor: 38
frigate.app                    INFO    : Capture process started for driveway: 41

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
blakeblackshearcommented, Jan 20, 2021

Wow. I can’t believe I missed that.

0reactions
neonpakcommented, Jan 20, 2021

I was referring to this line if config.cameras[name].clips.enabled. You are sending the state of config.cameras[name].clips.enabled to clips/state, snapshots/state and detect/state.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MQTT switch and sensor dont work after 2022.9 upgrade
I have this same issue. After 2022.9 upgrade, MQTT broker integrations are broken. I had many mqtt sensors that just stopped showing up...
Read more >
2022.2.4 MQTT Sensor Platform Broken · Issue #66128 - GitHub
I have a lot of MQTT entities (switches, sensors, binary sensors, lights) and there are no issues. My MQTT entities are "configured manually",...
Read more >
2022.2.4 MQTT Sensor Platform Broken - home-assistant/core
I updated to 2022.2.4 last night and it broke all my mqtt components. There's a fix but it's not current available so best...
Read more >
Home Assistant | Really anxious about this change to MQTT
cut and paste all mqtt entities files from original switches/, binary_sensors/, etc folders to newly created folders in step 1. This is easy...
Read more >
Buttons and Switches - Tasmota
SwitchMode 16: Send only MQTT message on inverted switch change. ... Depending if you are using a push-to-make button or push-to-break button, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found