Mqtt trigger an automation

Hi all!

First time im trying out MQTT. I have made myself a small project with an RFID chip and things are working good. But i struggle to use it to trigger an automation. My plan is to use the RFID to start and stop my alarm. But first i need to get the automation to trigger when i scan the chip.

I have set all the configurations and i do get a respons in Node-red debug when i scan my RFID chip.
Im not gonna use Node-red, i just used the debug function to see if it actually worked.

This is from debug. I did set my topic as “esprfid” in the software.

{"topic":"esprfid/send","payload":"{\"type\":\"access\",\"time\":1584569740,\"isKnown\":\"true\",\"access\":\"Admin\",\"username\":\"christian\",\"uid\":\"76e160a3\",\"door\":\"esp-rfid\"}","qos":0,"retain":false,"_msgid":"9795222b.c29b1"}

Just did a test -only- on the topic, but that doesnt work either.

- id: '1584564727759'
  alias: test
  description: ''
  trigger:
  - platform: mqtt
    topic: esprfid
  condition: []
  action:
  - data:
      message: test
    service: notify.mobile_app_sm_g965f

it’s not

that’s probably why it doesn’t work

Tried that also, but still doesnt work. Even when i got to developers tool and ty to listen too any of the topics it doesnt say anything either.

- id: '1584564727759'
  alias: test
  description: ''
  trigger:
  - platform: mqtt
    topic: esprfid/send
  condition: []
  action:
  - data:
      message: test
    service: notify.mobile_app_sm_g965f

subscribe to # and see what’s coming up and then use that topic

I dont get anything using # when i listen to MQTT. Leaves me to that something is wrong with my setup.

  1. I installed the Mosquitto broker addon. Config here:
logins:
  - username: mqtt
    password: mqtt
anonymous: true
customize:
  active: true
  folder: mosquitto
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false
  1. I went to configuration -> integration and added MQTT and set autodiscovery.
    Nothing shows up here but i assume my device doesnt apply for autodiscovery.

  2. I setup my esprfid (192.168.156.147) with the MQTT information.
    And it does connect to my broker.

1584623808: New connection from 192.168.156.147 on port 1883.
1584623808: New client connected from 192.168.156.147 as esp826604cdde (p2, c1, k15, u'mqtt').
  1. To test if my esorfid sends info too the broker i testet Node-red with a debug and also MQTT Explorer and get this info:
19.3.2020, 14:46:51node: Output debug
esprfid : msg : Object
object
topic: "esprfid"
payload: "{"type":"access","time":1584625613,"isKnown":"true","access":"Admin","username":"christian","uid":"76e160a3"}"
qos: 0
retain: false
_msgid: "170d4c1b.34e364"
  1. Basically just made an automation like this:
- id: '1584564727759'
  alias: test
  description: ''
  trigger:
  - platform: mqtt
    topic: esprfid
  condition: []
  action:
  - data:
      message: test
    service: notify.mobile_app_sm_g965f

So the broker gets the info, but looks like home assistant cant pick it up from the broker?
Since listening to “#” at the developers tool doesnt give anything, nor does “esprfid”

I have nothing in my configuration.yaml.

What can I say… Here’s my config (a default one I presume, just installed it)

logins: []
anonymous: false
customize:
  active: false
  folder: mosquitto
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false

and it works.
Subscribe to # and then send a message to your topic, you should see it arriving.

No it didnt work. But i found out something and maybe someone know why.
I realised it was home assistant that couldnt read the data sent to the Mosquitto broker.

So i removed MQTT from the “integration” section and added this manually to the config file:

mqtt:
  broker: 192.168.156.69
  username: mqtt
  password: mqtt

And now it works? Why on earth cant i use the “integration” page like everyone else?

that’s weird. and it’s great that you have found a temporary solution.
you can always create a new issue on Github.

TBH, I never used the mqtt integration. All my HA have their mqtt broker defined in configuration.yaml.

I can say almost the opposite - I kind of remember when mqtt config was in configuration.yaml but I followed the docs and switched to the integration config.
No issues either way.