164 lines
No EOL
3.7 KiB
YAML
164 lines
No EOL
3.7 KiB
YAML
# Pushbutton to switch Space-API-Status
|
|
|
|
esphome:
|
|
name: spacebutton
|
|
platform: ESP32
|
|
board: wemos_d1_mini32
|
|
on_boot:
|
|
priority: 750
|
|
then:
|
|
- script.execute: set_space_status
|
|
|
|
script:
|
|
- id: set_space_status
|
|
mode: restart
|
|
then:
|
|
- deep_sleep.prevent: deep_sleep_1
|
|
- wait_until:
|
|
condition:
|
|
wifi.connected:
|
|
timeout: 8s
|
|
- http_request.post:
|
|
url: !secret space_url
|
|
headers:
|
|
Content-Type: application/json
|
|
Authorization: !secret space_token
|
|
json:
|
|
open: !lambda |-
|
|
if(id(spacebutton).state) {
|
|
return "true";
|
|
} else {
|
|
return "false";
|
|
}
|
|
message: ""
|
|
trigger_person: "Space-Button"
|
|
verify_ssl: false
|
|
on_response:
|
|
then:
|
|
- logger.log:
|
|
format: "POST Response status: %d"
|
|
args:
|
|
- status_code
|
|
# ändern led red und green status
|
|
- http_request.get:
|
|
url: !secret space_url
|
|
headers:
|
|
Content-Type: application/json
|
|
verify_ssl: false
|
|
on_response:
|
|
then:
|
|
- lambda: |-
|
|
char stat = id(http_request_data).get_string()[0];
|
|
if (stat == '1') {
|
|
ESP_LOGD("spacestatus", "OPEN");
|
|
id(light_red).turn_off().perform();
|
|
id(light_green).turn_on().perform();
|
|
} else {
|
|
ESP_LOGD("spacestatus", "CLOSED");
|
|
id(light_red).turn_on().perform();
|
|
id(light_green).turn_off().perform();
|
|
}
|
|
- logger.log:
|
|
format: "GET Response status: %d"
|
|
args:
|
|
- status_code
|
|
- delay: 30s
|
|
- deep_sleep.allow: deep_sleep_1
|
|
|
|
#ota:
|
|
# safe_mode: True
|
|
# password: !secret ota_password
|
|
|
|
#status_led:
|
|
# pin: GPIO2
|
|
|
|
wifi:
|
|
ssid: !secret wifi_ssid
|
|
password: !secret wifi_password
|
|
fast_connect: true
|
|
|
|
mqtt:
|
|
broker: !secret mqtt_url
|
|
username: !secret mqtt_user
|
|
password: !secret mqtt_password
|
|
discovery: false
|
|
|
|
mdns:
|
|
disabled: true
|
|
|
|
#web_server:
|
|
# port: 80
|
|
|
|
#logger:
|
|
# level: DEBUG
|
|
|
|
http_request:
|
|
useragent: esphome/spacebutton
|
|
timeout: 5s
|
|
id: http_request_data
|
|
|
|
sensor:
|
|
- platform: adc
|
|
pin: A0
|
|
attenuation: 11db
|
|
device_class: battery
|
|
id: battery_level
|
|
name: "vcc"
|
|
filters:
|
|
- lambda: |-
|
|
float alarm_value = 3.1;
|
|
ESP_LOGD("battery", "Alarm value: %f", alarm_value);
|
|
ESP_LOGD("battery", "Battery level: %f", x);
|
|
if (x < alarm_value) {
|
|
id(light_status).turn_on().perform();
|
|
ESP_LOGD("battery", "LOW");
|
|
} else {
|
|
id(light_status).turn_off().perform();
|
|
ESP_LOGD("battery", "NORMAL");
|
|
}
|
|
return x;
|
|
|
|
binary_sensor:
|
|
- platform: gpio
|
|
pin:
|
|
number: GPIO27
|
|
mode: INPUT_PULLUP
|
|
inverted: True
|
|
id: spacebutton
|
|
name: Spacebutton
|
|
filters:
|
|
- delayed_on_off: 100ms
|
|
on_state:
|
|
then:
|
|
- script.execute: set_space_status
|
|
|
|
light:
|
|
- platform: binary
|
|
id: light_green
|
|
output: gpio_green
|
|
restore_mode: ALWAYS_OFF
|
|
- platform: binary
|
|
id: light_red
|
|
output: gpio_red
|
|
restore_mode: ALWAYS_OFF
|
|
- platform: binary
|
|
id: light_status
|
|
output: gpio_blue
|
|
restore_mode: ALWAYS_OFF
|
|
|
|
output:
|
|
- id: gpio_green
|
|
platform: gpio
|
|
pin: GPIO14
|
|
- id: gpio_red
|
|
platform: gpio
|
|
pin: GPIO33
|
|
- id: gpio_blue
|
|
platform: gpio
|
|
pin: GPIO2
|
|
|
|
deep_sleep:
|
|
run_duration: 15s
|
|
wakeup_pin: GPIO27
|
|
wakeup_pin_mode: INVERT_WAKEUP
|
|
id: deep_sleep_1 |