feat: update ota config to new format
This commit is contained in:
parent
2eff076d5b
commit
582d9c4714
|
@ -18,16 +18,16 @@ esphome:
|
||||||
on_boot:
|
on_boot:
|
||||||
- priority: 600
|
- priority: 600
|
||||||
then:
|
then:
|
||||||
- light.addressable_set: { id: status_led, red: 0%, green: 0%, blue: 100% }
|
- light.turn_on: { id: status_led, red: 0%, green: 0%, blue: 100% }
|
||||||
- priority: -100
|
- priority: -100
|
||||||
then:
|
then:
|
||||||
- if:
|
- if:
|
||||||
condition:
|
condition:
|
||||||
switch.is_on: mlock_${name_of_board}_switch
|
switch.is_on: mlock_${name_of_board}_switch
|
||||||
then:
|
then:
|
||||||
- light.addressable_set: { id: status_led, red: 0%, green: 100%, blue: 0% }
|
- light.turn_on: { id: status_led, red: 0%, green: 100%, blue: 0% }
|
||||||
else:
|
else:
|
||||||
- light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
- light.turn_on: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
||||||
|
|
||||||
# Enable logging
|
# Enable logging
|
||||||
logger:
|
logger:
|
||||||
|
@ -37,6 +37,7 @@ api:
|
||||||
key: $api_enckey
|
key: $api_enckey
|
||||||
|
|
||||||
ota:
|
ota:
|
||||||
|
- platform: esphome
|
||||||
password: $ota_password
|
password: $ota_password
|
||||||
|
|
||||||
wifi:
|
wifi:
|
||||||
|
@ -65,6 +66,7 @@ http_request:
|
||||||
useragent: esphome
|
useragent: esphome
|
||||||
timeout: 2s
|
timeout: 2s
|
||||||
id: http_request_data
|
id: http_request_data
|
||||||
|
verify_ssl: false
|
||||||
|
|
||||||
globals:
|
globals:
|
||||||
- id: my_token
|
- id: my_token
|
||||||
|
@ -81,7 +83,7 @@ rc522_spi:
|
||||||
cs_pin: GPIO15
|
cs_pin: GPIO15
|
||||||
on_tag:
|
on_tag:
|
||||||
then:
|
then:
|
||||||
- light.addressable_set:
|
- light.turn_on:
|
||||||
id: status_led
|
id: status_led
|
||||||
red: 100%
|
red: 100%
|
||||||
green: 100%
|
green: 100%
|
||||||
|
@ -97,13 +99,13 @@ rc522_spi:
|
||||||
json:
|
json:
|
||||||
role_id: $vault_role_id
|
role_id: $vault_role_id
|
||||||
secret_id: $vault_secret_id
|
secret_id: $vault_secret_id
|
||||||
verify_ssl: false
|
|
||||||
on_response:
|
on_response:
|
||||||
# fetch token from response, store into my_token
|
# fetch token from response, store into my_token
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
|
json::parse_json(body, [](JsonObject root) -> bool {
|
||||||
id(my_token) = (const char*) root["auth"]["client_token"];
|
id(my_token) = (const char*) root["auth"]["client_token"];
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
# use the token to get json of scanned tag from vault
|
# use the token to get json of scanned tag from vault
|
||||||
- http_request.get:
|
- http_request.get:
|
||||||
|
@ -111,16 +113,16 @@ rc522_spi:
|
||||||
return ((std::string) "https://vault.ctdo.de/v1/maschinenlock/" + id(my_tag));
|
return ((std::string) "https://vault.ctdo.de/v1/maschinenlock/" + id(my_tag));
|
||||||
headers:
|
headers:
|
||||||
X-Vault-Token: !lambda return id(my_token).c_str();
|
X-Vault-Token: !lambda return id(my_token).c_str();
|
||||||
verify_ssl: false
|
|
||||||
on_response:
|
on_response:
|
||||||
then:
|
then:
|
||||||
- if:
|
- if:
|
||||||
condition:
|
condition:
|
||||||
lambda: 'return status_code == 200;'
|
lambda: 'return response->status_code == 200;'
|
||||||
then: # when found, check if machine is allowed, turn on output or blink LED red
|
then: # when found, check if machine is allowed, turn on output or blink LED red
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
|
json::parse_json(body, [](JsonObject root) -> bool {
|
||||||
id(may_switch_output) = root["data"]["mlock-$name_of_board"];
|
id(may_switch_output) = root["data"]["mlock-$name_of_board"];
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
- if:
|
- if:
|
||||||
condition:
|
condition:
|
||||||
|
@ -150,25 +152,21 @@ rc522_spi:
|
||||||
- repeat:
|
- repeat:
|
||||||
count: 3
|
count: 3
|
||||||
then:
|
then:
|
||||||
- light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
- light.turn_on: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
||||||
- delay: 0.1s
|
- light.turn_on: { id: status_led, red: 0%, green: 0%, blue: 0% }
|
||||||
- light.addressable_set: { id: status_led, red: 0%, green: 0%, blue: 0% }
|
|
||||||
- delay: 0.1s
|
|
||||||
else: # vault returns 404 on missing/unknown Tag so blink LED
|
else: # vault returns 404 on missing/unknown Tag so blink LED
|
||||||
- repeat:
|
- repeat:
|
||||||
count: 3
|
count: 3
|
||||||
then:
|
then:
|
||||||
- light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
- light.turn_on: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
||||||
- delay: 0.5s
|
- light.turn_on: { id: status_led, red: 0%, green: 0%, blue: 0% }
|
||||||
- light.addressable_set: { id: status_led, red: 0%, green: 0%, blue: 0% }
|
|
||||||
- delay: 0.5s
|
|
||||||
- if: # return LED to switch state before
|
- if: # return LED to switch state before
|
||||||
condition:
|
condition:
|
||||||
switch.is_on: mlock_${name_of_board}_switch
|
switch.is_on: mlock_${name_of_board}_switch
|
||||||
then:
|
then:
|
||||||
- light.addressable_set: { id: status_led, red: 0%, green: 100%, blue: 0% }
|
- light.turn_on: { id: status_led, red: 0%, green: 100%, blue: 0% }
|
||||||
else:
|
else:
|
||||||
- light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
- light.turn_on: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
||||||
|
|
||||||
# switch component for the output state
|
# switch component for the output state
|
||||||
switch:
|
switch:
|
||||||
|
@ -188,7 +186,7 @@ binary_sensor:
|
||||||
id: ${name_of_board}gpio_input_ausschalter
|
id: ${name_of_board}gpio_input_ausschalter
|
||||||
on_press:
|
on_press:
|
||||||
- switch.turn_off: mlock_${name_of_board}_switch
|
- switch.turn_off: mlock_${name_of_board}_switch
|
||||||
- light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
- light.turn_on: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
||||||
|
|
||||||
# a template sensor for showing the current switch state (read only)
|
# a template sensor for showing the current switch state (read only)
|
||||||
- platform: template
|
- platform: template
|
||||||
|
@ -205,7 +203,7 @@ button:
|
||||||
id: ${name_of_board}_btn_ausschalter
|
id: ${name_of_board}_btn_ausschalter
|
||||||
on_press:
|
on_press:
|
||||||
- switch.turn_off: mlock_${name_of_board}_switch
|
- switch.turn_off: mlock_${name_of_board}_switch
|
||||||
- light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
- light.turn_on: { id: status_led, red: 100%, green: 0%, blue: 0% }
|
||||||
|
|
||||||
light:
|
light:
|
||||||
- platform: neopixelbus
|
- platform: neopixelbus
|
||||||
|
|
Loading…
Reference in New Issue