MQTT Sensor Light - add mqtt sensor without configuration yaml


I want simulate light mqtt sensor in my node red.

I try do this using that article MQTT Light - Home Assistant

in configuration.yaml, after reboot, i have that in my list of registry entity


# Loads default set of integrations. Do not remove.


# Load frontend themes from the themes folder
  themes: !include_dir_merge_named themes

# Text to speech
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml

    - name: "Office light 4"
      object_id: "office_light_4"
      unique_id: "office_light_4"
      state_topic: "office_4/light/status"
      command_topic: "office_4/light/switch"
      brightness_state_topic: 'office_4/light/brightness'
      brightness_command_topic: 'office_4/light/brightness/set'
      qos: 0
      payload_on: "ON"
      payload_off: "OFF"
      optimistic: true

in list of entity

okay, now i try do this that same, but only discovery when he show in mqtt server.

my simple program at

function block “office light 5”

msg.topic = "office_light_5/config"
msg.payload = {
    "device_class": "None", 
    "object_id": "office_light_5",
    "unique_id": "office_light_5",
    "name": "Office light 5", 
    "state_topic": "office_5/light/status", 
    "command_topic": "office_5/light/switch",
    "brightness_state_topic": 'office_5/light/brightness',
    "brightness_command_topic": 'office_5/light/brightness/set',
    "qos": 0,
    "payload_on": "ON",
    "payload_off": "OFF",
    "optimistic": true
return msg;

function block ‘set “office_5/light/brightness/set” value’

msg.topic = "office_5/light/brightness/set"
msg.payload  = 111
return msg;

function block ‘set “office_5/light/switch” value’

msg.topic = "office_5/light/switch"
msg.payload  = "ON"
return msg;

And i see that message in my mqtt broker

What i have done wrong? Do you have idea? with more simple sensor ( like temperature ) that work, but for light i cannot break a wall of unknowledge…

What is the issue actually?

Is your device not discovered?

Discovery (config) topic should be:


With everything quoted correctly (double-quotes around everything) from my command line:

pi:~$ mosquitto_pub -h -t 'homeassistant/light/office_light_5/config' -m '{
      "device_class": "None",
      "object_id": "office_light_5",
      "unique_id": "office_light_5",
      "name": "Office light 5",
      "state_topic": "office_5/light/status",
      "command_topic": "office_5/light/switch",
      "brightness_state_topic": "office_5/light/brightness",
      "brightness_command_topic": "office_5/light/brightness/set",
      "qos": "0",
      "payload_on": "ON",
      "payload_off": "OFF",
      "optimistic": "true"


ah - ofcourse ! That work, thank you :blush:

1 Like