Issues with MQTT (1)

I have an MQTT script to basically power cycle a smart plug if an MQTT request is sent by Blue Iris.

The whole automation works with the script that I made in Home Assistant when I tested it. And when I do a test MQTT request on Blue Iris, MQTT explorer has a message in the topic section for homeassistant, as expected. But the problem is that even though it seems like home assistant received the MQTT packet, it doesn’t do anything.

MQTT Broker logs don’t say anything about a blocked connection to the BI host.

My only assumption could be that ‘platform: mqtt’ could be something different for MQTT Broker. But I really don’t know at this point. Logs are a ghost town in Home Assistant.

Script:

power_cycle_smart_plug:
  sequence:
    - service: switch.turn_off
      data_template:
        entity_id: switch.kasa_smart_wi_fi_plug_{{plug_id}}
    - delay: '00:00:05'
    - service: switch.turn_on
      data_template:
        entity_id: switch.kasa_smart_wi_fi_plug_{{plug_id}}

Automation:

  - id: power_cycle_smart_plug_1
    alias: Power Cycle Smart Plug 1
    trigger:
      platform: mqtt
      topic: homeassistant/switch/kasa_smart_wi_fi_plug_1/control
      payload: power_cycle
    action:
      - service: script.turn_on
        data_template:
          entity_id: script.power_cycle_smart_plug
          variables:
            plug_id: 1

Maybe show your script

Yeah, guess that would help. Updated post.

Does the automation trigger?

These traces are also available for scripts.

You have exactly power_cycle as the message in the homeassistant/switch/kasa_smart_wi_fi_plug_1/control topic, right?

And it’s not retained?

Post a screenshot of the topic and payload displayed by MQTT Explorer.

It will only trigger when it’s run manually on Home Assistant.

image

Yep.

The topic you’re using is uncomfortably similar to the topic that Home Assistant uses for MQTT Discovery. I suggest you use a different topic to avoid any potential overlap with MQTT Discovery (i.e. a malformed discovery topic and and/or discovery payload will be rejected).

Here’s how to confirm Home Assistant received the payload.

  1. Go to Settings > Devices and Services > Integrations
  2. Click the MQTT integration (if it’s not present then there’s the source of the problem)
  3. Click Configure
  4. In Listen to a Topic, enter your topic in Topic to Subscribe to.
  5. Click Start Listening
  6. Use an MQTT client to publish a payload to the topic
  7. The payload should appear in the window
  8. Click Stop Listening

If it received it but it fails to trigger the automation then I suggest you change the topic so that it doesn’t look like a discovery topic. For example:

ha/switch/kasa_smart_wi_fi_plug_1/control

Yeah I have never understood why people put their control topics under the discovery topic.

Ditto. I have seen this happen more than once. Uncanny how they happen to choose the same topic structure as MQTT Discovery.

Guess I’m not sure what window you’re talking about, but the page doesn’t seem to be changing when I send the topic on Blue Iris.

So, I guess I’m stuck on 7.

The window where the subscribed messages appear once you complete step 5.

If the message is not appearing there, HA is not receiving it.

I’m not really sure what else to do if it’s not receiving anything. Can’t be a firewall rule, it’s disabled on the VM and host machine. I don’t think HA has a software firewall.

Change the topic to something other than the home assistant discovery topic, as Taras suggested.

Well, I changed it to blueiris/camera_status_kasa_smart_wi_fi_plug_1/control
The automation still works when triggered manually. Still the same problem as before. It won’t accept MQTT requests.

Have you actually set up the mqtt connection to your broker?

Could be to do with auth.

Is this the first time you are trying to get Home Assistant to work with MQTT?

If it is then we need to confirm that you have configured the MQTT integration properly. The result of the experiment I had asked you to perform implies Home Assistant is not connected to the MQTT broker.