Das folgende ESPHome Programm ist für eine NodeMCU mit einem PIR und nicht adressierbaren RGB LEDs.
Der Bewegungsmelder ist nur aktiv nach Sonnenuntergang. Über einen Software-switch lassen sich die leds über Home Assistant auch dauerhaft aktivieren. Die Light-Komponente lässt sich aus HA heraus natürlich auch wie gewohnt manuell steuern.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
esphome:
name: test
platform: ESP8266
board: nodemcuv2
wifi:
ssid: !secret WLanSSID
password: !secret WLanPassword
ap:
ssid: "RGB Sun Pir"
password: "gWef1LCbEILB"
captive_portal:
logger:
api:
password: !secret HA_API_Password
ota:
password: !secret HA_OTA_Password
sun:
# Hier die Koordinaten an euren Standort anpassen damit Sonnenauf-/untergang bestimmt werden kann
latitude: 51.138374°
longitude: 7.185790°
time:
- platform: homeassistant
id: local_time
binary_sensor:
- platform: gpio
pin: D1
name: "Bewegungsmelder"
device_class: motion
id: rgb_pir
on_press:
then:
- if:
condition:
- sun.is_below_horizon:
then:
- script.execute: switch_n_rgb_script
light:
- platform: rgb
name: "RGB"
red: rgb_1
green: rgb_2
blue: rgb_3
id: rgb_led
output:
- platform: esp8266_pwm
id: rgb_1
pin: D5
- platform: esp8266_pwm
id: rgb_2
pin: D6
- platform: esp8266_pwm
id: rgb_3
pin: D2
# Helper um per HA das Abschalten per timeout generell zu verhindern
switch:
- platform: gpio
pin: D3
name: "n-LEDs dauerhaft an"
id: n_leds_daueran
on_turn_on:
- light.turn_on: rgb_led
on_turn_off:
- light.turn_off: rgb_led
# Script mit Mode=restart, damit der Timeout bei jeder erneuten Bewegung zurückgesetzt wird.
# Wenn also das Licht eingeschaltet wurde, aber in den 2 Minuten delay erneut eine Bewegung erkannt wird,
# wird das Script abgebrochen und neu gestartet, wodurch die 2 Minuten Wartezeit erneut beginnen
script:
- id: switch_n_rgb_script
mode: restart
then:
- light.turn_on: rgb_led
- delay: 2min
- if:
condition:
switch.is_off: n_leds_daueran
then:
- light.turn_off: rgb_led