MQTT Sensor Light - add mqtt sensor without configuration yaml

Hi,

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

configuration.yaml

# Loads default set of integrations. Do not remove.
default_config:

cloud:

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

# Text to speech
tts:
  - platform: google_translate

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

mqtt:
  light:
    - 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 node.red

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:

homeassistant/light/office_light_5/config

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

pi:~$ mosquitto_pub -h 192.168.1.7 -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"
      }'

2 Likes

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

1 Like