BH1750 Light Sensor + Mosquitto broker

Hi,

this is my first try to connect a sensor via MQTT to HA. The Script is reading the Sensor-Data and is sending this to HA. But now I’m lost. How to use this data in a automation oder lovelace? There is no entity created which I can use. Any help is appreciated. This what I have so far:

sensor.yaml

- platform: mqtt
  state_topic: "kitchen/light_intensity"
  name: Kitchen Light Intensity
  device_class: illuminance

python-script (running on a different Raspi3)

#!/usr/bin/python3

# Import package
import time
import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish
import board
import adafruit_bh1750

# Def
broker = "***"
username='***'
password='***'
clientid='python-mqtt-bh1750'
state_topic = "kitchen/light_intensity"

delay = 30

def readSensor():
    i2c = board.I2C()
    lightsensor = adafruit_bh1750.BH1750(i2c)
    return lightsensor.lux


# MQTT
client = mqtt.Client(clientid)
client.username_pw_set(username, password)
client.connect(broker)
client.loop_start()

while True:
    print(readSensor())
    time.sleep(1)
    sensor_data = readSensor()
    client.publish(state_topic, str(sensor_data))
    time.sleep(delay)

Hi
In your configuration.yaml, do you include sensor.yaml?

Armin

Magically, the entity is now available. No idea why, probably just had to wait a bit.