Initial commit
This commit is contained in:
commit
b3da202bec
4 changed files with 197 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
secrets.yaml
|
24
README.md
Normal file
24
README.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Pushbutton to switch Space-API-Status
|
||||
Hardware-Schalter, um den Space-API-Status umzuschalten. Nach dem Umschalten wird 30 Sekunden lang der Status aus der Space-API angezeigt. Danach wird der ESP in den Deep Sleep versetzt. Somit kann der ESP auch mit einer Batterie/Akku verwendet werden.
|
||||
|
||||
## Funktionsweise
|
||||
1. Der Space-API wird per POST request ein JSON übermittelt `{"open":"false","trigger_person":"Space-Button","message":""}`. Dabei wird ein Bearer Token für die Authentisierung verwendet.
|
||||
2. Der Space-API Status wird abgerufen. Da es Probleme mit der Auswertung des JSON-Strings gab, wird im Beispiel nur 1 oder NULL zurückgegeben und ausgewertet.
|
||||
|
||||
## Einsparungsmöglichkeiten
|
||||
Um nach dem Wakeup schneller den Status anzeigen zu können, sind folgende Optimierungen möglich:
|
||||
|
||||
- kein DHCP
|
||||
- kein DNS resolve
|
||||
- kein MQTT
|
||||
|
||||
bereits umgesetzt:
|
||||
- WiFi-Fastconnect
|
||||
- HTTP deaktiviert
|
||||
- mdns deaktiviert
|
||||
- kein Logging
|
||||
|
||||
## Anzeige
|
||||
Rot: Space geschlossen
|
||||
Grün: Space offen
|
||||
Blau: Batterie leer
|
8
secrets.yaml.example
Normal file
8
secrets.yaml.example
Normal file
|
@ -0,0 +1,8 @@
|
|||
wifi_ssid: WiFi
|
||||
wifi_password: SECRET
|
||||
space_url: https://spaceapi/
|
||||
space_token: Bearer TOKEN
|
||||
mqtt_url: mqtt.xyz
|
||||
mqtt_user: mqtt
|
||||
mqtt_password: SECRET
|
||||
ota_password: SECRET
|
164
spacebutton_d1_esp32.yaml
Normal file
164
spacebutton_d1_esp32.yaml
Normal file
|
@ -0,0 +1,164 @@
|
|||
# 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
|
Loading…
Add table
Add a link
Reference in a new issue