mega-hz
(Wolfram)
1
Hello,
i just started with ESPhome and HA.
I already got it running to edit a demo sample program to switch 2 LEDs on ESP-Board.
esphome:
name: test_esp
platform: ESP8266
board: d1_mini
wifi:
ssid: "-------------"
password: "--------------"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Test Esp Fallback Hotspot"
password: "1BvuZaiGlfkd"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "---------"
ota:
password: "--------------"
web_server:
port: 80
switch:
- platform: gpio
name: "LED1"
pin:
number: 16
inverted: yes
- platform: gpio
name: "LED2"
pin:
number: 2
inverted: yes
Now i can switch the onboard-LED and also the LED on the ESP8266 Module.
How can i let switch one LED automatic on this : - sun.is_above_horizon:
?
I am not yet good in the syntax so it would be great to get some help.
Thank you,
Wolfram.
tom_l
2
You will need the sun component:
And then to automate your LED switch use the switch turn on/off actions:
So something like this:
time:
- platform: homeassistant
sun:
latitude: 48.8584° # your lat and lon here
longitude: 2.2945°
on_sunrise:
- then:
- switch.turn_on: led2
on_sunset:
- then:
- switch.turn_off: led2
mega-hz
(Wolfram)
3
thank you, but i get an error:
Couldn’t find ID ‘LED2’. Please check you have defined an ID with that name in your configuration.
id: LED2 (source myfirst.yaml:52)
Here my Listing:
esphome:
name: test_esp
platform: ESP8266
board: d1_mini
wifi:
ssid: "--------"
password: "--------"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Test Esp Fallback Hotspot"
password: "1BvuZaiGlfkd"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "--------"
ota:
password: "--------"
web_server:
port: 80
switch:
- platform: gpio
name: "LED1"
pin:
number: 16
inverted: yes
- platform: gpio
name: "LED2"
pin:
number: 2
inverted: yes
time:
- platform: homeassistant
sun:
latitude: 52.xxxxx° # your lat and lon here
longitude: 8.xxxxxx°
on_sunrise:
- then:
- switch.turn_off: LED2
on_sunset:
- then:*
- switch.turn_on: LED2*
tom_l
4
Add ids to your switches to use them in other parts of esphome:
switch:
- platform: gpio
name: "LED1"
id: led1
pin:
number: 16
inverted: yes
- platform: gpio
name: "LED2"
id: led2
pin:
number: 2
inverted: yes
mega-hz
(Wolfram)
5
OK, thank you, that works (copiles without errors)
But should`nd be the LED always on regardless of switch state?
Or does the switch-state override the sunrise?
Or is it better to use above_horizont and if yes, how is the syntax for that?
tom_l
6
If you don’t wan the LEDs to be able to be manually controlled as a switch, use an output component instead.
n1k5y
(Nikola)
7
You can also just use internal: true
and it won’t be exposed to HA
mega-hz
(Wolfram)
8
Well, it should show the state in HA,
i made it like this:
switch:
- platform: gpio
name: "LED1"
id: led1
pin:
number: 16
inverted: yes
- platform: gpio
name: "LED2"
id: led2
pin:
number: 2
inverted: yes
output:
- platform: gpio
id: Ausgang2
pin:
number: 2
inverted: yes
time:
- platform: homeassistant
sun:
latitude: 52.xxxxxxx° # your lat and lon here
longitude: 8.xxxxx1°
on_sunrise:
- then:
- output.turn_off: Ausgang2
on_sunset:
- then:
- output.turn_on: Ausgang2
But i am asking me, what should be the better way to do something like this:
Should i only program the funtions to the esp8266 and use HA Automation or should i put this into each esp?
How can i display-only (instead of a switch) the state of Ausgang2(LED2)?
Is there a icon like a bulb?