Publish "sensor value" to MQTT to work as Tag

Hello together,

I have an Sensor (sensor.esp8266_reader) that gets an UID from of NFC Tag (only the UID) like

E00302400860

I would like to get this UID working as “Tag” afaik i need to get the UID somehow pubished to MQTT so that HA will be able to detect is via Auto Discovery.

So my question is:
HOW must the “Service: MQTT Publish” look like to send the Sensor Value (sensor.esp8266_reader)

service: mqtt.publish
data: {}

There’s really no way to answer this because it depends on what format the data in the topic should be. And that depends on what devices are reading the topics, and what they expect the data format to be. You just provide the payload: in data, and the format of payload depends on everything I said above.

I try it again, i only have the given Sensor that as an NFC UID

I would Like to use this UID as TAG, so i could Run an Automation everytime when the Sensor has a specific UID.

Sure i could use the Sensor value as Trigger too.

If you want to use the native HA Tag feature and a home made sensor sending MQTT then you should look at MQTT Tag Scanner - Home Assistant

If you do not care too much for if HA thinks it is a tag but just want to run automations for specific mqtt messages sent by an mqtt device then you can define any MQTT sensor and use the value from that.

I have an mqtt sensor yaml file (file called mqtt_sensors.yaml inside a folder mqtt included from configuration.yaml with the line mqtt: !include_dir_merge_named mqtt)

sensor:
  - name: "nfcmqtt"
    state_topic: "alarm/nfcuid"
    unique_id: "nfcmqtt"

My little home made nfc scanner simply sends the scanned UID to the alarm/nfcid topic.

And I have an automation

- id: 'NFC_Reader'
  alias: 'NFC Reader'
  initial_state: true
  trigger:
    platform: mqtt
    topic: "alarm/nfcuid"
  condition:
    - condition: template
      value_template: !secret nfc_alarm_values
      #in secerets we define nfc_alarm_values: "{{ trigger.payload in ['aaaaaaaa', 'bbbbbbbb', 'cccccccc', 'dddddddd'] }}"

  action:
    - service: alarm_control_panel.alarm_disarm
      entity_id: alarm_control_panel.house_alarm

That does not use the tag feature. It is just an MQTT sensor and simple automation. But simple is beautiful and hard to break when the devs make breaking changes in a more complex feature like tag