|
|
@@ -21,11 +21,11 @@ project_name = 'Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon'
|
|
|
project_url = 'https://github.com/ThomDietrich/miflora-mqtt-daemon'
|
|
|
|
|
|
parameters = OrderedDict([
|
|
|
- (MI_LIGHT, dict(name="LightIntensity", name_pretty='Sunlight Intensity', typeformat='%d', unit='lux')),
|
|
|
- (MI_TEMPERATURE, dict(name="AirTemperature", name_pretty='Air Temperature', typeformat='%.1f', unit='°C')),
|
|
|
- (MI_MOISTURE, dict(name="SoilMoisture", name_pretty='Soil Moisture', typeformat='%d', unit='%')),
|
|
|
+ (MI_LIGHT, dict(name="LightIntensity", name_pretty='Sunlight Intensity', typeformat='%d', unit='lux', device_class="illuminance")),
|
|
|
+ (MI_TEMPERATURE, dict(name="AirTemperature", name_pretty='Air Temperature', typeformat='%.1f', unit='°C', device_class="temperature")),
|
|
|
+ (MI_MOISTURE, dict(name="SoilMoisture", name_pretty='Soil Moisture', typeformat='%d', unit='%', device_class="humidity")),
|
|
|
(MI_CONDUCTIVITY, dict(name="SoilConductivity", name_pretty='Soil Conductivity/Fertility', typeformat='%d', unit='µS/cm')),
|
|
|
- (MI_BATTERY, dict(name="Battery", name_pretty='Sensor Battery Level', typeformat='%d', unit='%'))
|
|
|
+ (MI_BATTERY, dict(name="Battery", name_pretty='Sensor Battery Level', typeformat='%d', unit='%', device_class="battery"))
|
|
|
])
|
|
|
|
|
|
if False:
|
|
|
@@ -287,7 +287,6 @@ elif reporting_mode == 'homeassistant-mqtt':
|
|
|
for [flora_name, flora] in flores.items():
|
|
|
topic_path = '{}/sensor/{}'.format(base_topic, flora_name)
|
|
|
base_payload = {
|
|
|
- "device_class": "sensor",
|
|
|
"state_topic": "{}/state".format(topic_path).lower()
|
|
|
}
|
|
|
for sensor, params in parameters.items():
|
|
|
@@ -295,6 +294,8 @@ elif reporting_mode == 'homeassistant-mqtt':
|
|
|
payload['unit_of_measurement'] = params['unit']
|
|
|
payload['value_template'] = "{{ value_json.%s }}" % (sensor, )
|
|
|
payload['name'] = "{} {}".format(flora_name, sensor.title())
|
|
|
+ if 'device_class' in params:
|
|
|
+ payload['device_class'] = params['device_class']
|
|
|
mqtt_client.publish('{}/{}_{}/config'.format(topic_path, flora_name, sensor).lower(), json.dumps(payload), 1, True)
|
|
|
|
|
|
print_line('Initialization complete, starting MQTT publish loop', console=False, sd_notify=True)
|