I have built an ambient light sensor that delivers the light level (lux) to Home Assistant via an MQTT message every 5 minutes. On the face of it, it works well.
sensor:
- name: "Hall ambient light"
unique_id: 123456789
state_topic: "home/hall/ambient"
value_template: '{{ value_json.illuminance | int }}'
qos: 0
unit_of_measurement: 'lux'
I have an automation that is triggered by the arrival of this MQTT message and switches a light on/off depending on the light level. This also appears to work.
- id: '1723227061809'
alias: Hall Ambient Light
description: Turns hall table lamp on/off depending on amount of ambient light
trigger:
- platform: mqtt
topic: home/hall/ambient
- platform: time
at: 06:30:00
- platform: mqtt
topic: home/hall/ambient
condition:
- condition: time
after: 06:29:00
before: '22:00:00'
action:
- if:
- condition: numeric_state
entity_id: sensor.ambient_light
below: 25
then:
- action: homeassistant.turn_on
metadata: {}
data: {}
target:
entity_id: switch.hall_table_lamp
else:
- action: homeassistant.turn_off
metadata: {}
data: {}
target:
entity_id: switch.hall_table_lamp
mode: single
However, I have discovered that the automation is not responding to the lux value in the current message, but instead it is reading the stored lux value received 5 minutes earlier.
Can anyone let me know how to get the automation to read the current lux value held within the MQTT message? Thank you.