Plant monitor alert with Home Assistant and M5Stack Atom Lite
After following this guide on YouTube from The Home Automation Guy, I thought I’d try and take it one step further and add an alert function using the M5Stack’s LED.
In the ESP Home configuration for the Atom, I added the following section to add a control for the LED:
light:
- platform: neopixelbus
type: GRB
variant: SK6812
pin: 27
num_leds: 1
id: status_led
name: "Status LED"
internal: False
default_transition_length: 2s
effects:
- pulse:
name: "Slow Pulse"
transition_length: 1s
update_interval: 3s
initial_state:
state: False
This appears in Home Assistant as a light
entity.
As the M5Stack Atom Lite is in the bedroom (mounted behind the TV), I didn’t want it lighting up in the night when we’re sleeping. I added a Helper Schedule defining awake hours - schedule.awake_hours
.
Then I added an automation to Home Assistant using the automation builder. It produced the following YAML for me:
alias: Water Swiss Cheese Plant
description: ""
triggers:
- trigger: state
entity_id:
- plant.swiss_cheese_plant
from: null
to: null
id: swiss_cheese_plant_state_change
- trigger: state
entity_id:
- schedule.awake_hours
from: null
to: null
conditions: []
actions:
- if:
- condition: state
entity_id: schedule.awake_hours
state: "on"
then:
- if:
- condition: state
entity_id: plant.swiss_cheese_plant
state: problem
then:
- action: light.turn_on
metadata: {}
data:
rgb_color:
- 255
- 0
- 0
effect: Slow Pulse
target:
entity_id: light.m5stackatom_status_led
else:
- if:
- condition: state
entity_id: plant.swiss_cheese_plant
state: ok
- condition: trigger
id:
- swiss_cheese_plant_state_change
then:
- action: light.turn_on
metadata: {}
data:
rgb_color:
- 0
- 255
- 0
effect: None
target:
entity_id: light.m5stackatom_status_led
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- action: light.turn_off
metadata: {}
data: {}
target:
entity_id: light.m5stackatom_status_led
else:
- action: light.turn_off
metadata: {}
data: {}
target:
entity_id: light.m5stackatom_status_led
else:
- action: light.turn_off
metadata: {}
data: {}
target:
entity_id: light.m5stackatom_status_led
mode: single
This will be triggered either by the plant state changing or by the awake hours schedule changing.
If it is within the awake hours (schedule.awake_hours
is on) then it checks to see if the plant is in a problem state and if so turns on the led with a red slow pulse effect. If the plant isn’t in a problem state then it checks to see if the plant triggered the automation and if so sets the led to green for one minute then turns it off. If the plant is in an ok state and didn’t trigger the automation (i.e. the schedule did) then the led is turned off.
Finally if the automation is triggered but it’s outside the schedule time (or the schedule changes to off) then the led is turned off.