Compare commits

..

1 Commits

Author SHA1 Message Date
neri 629bfbed9e wip: reduce code 2024-03-02 02:16:31 +01:00
1 changed files with 6 additions and 8 deletions

View File

@ -92,6 +92,7 @@ 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:
@ -106,11 +107,12 @@ rc522_spi:
headers: headers:
X-Vault-Token: !lambda return id(my_token).c_str(); X-Vault-Token: !lambda return id(my_token).c_str();
on_response: on_response:
# when found, check if machine is allowed, turn on output or blink LED red
then: then:
- if: - if:
condition: condition:
lambda: 'return status_code == 200;' lambda: 'return status_code == 200;'
then: # when found, check if machine is allowed, turn on output or blink LED red then:
- lambda: |- - lambda: |-
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) { json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
id(may_switch_output) = root["data"]["mlock-$name_of_board"]; id(may_switch_output) = root["data"]["mlock-$name_of_board"];
@ -136,7 +138,7 @@ rc522_spi:
- delay: 0.5s - delay: 0.5s
- light.addressable_set: { id: status_led, red: 0%, green: 0%, blue: 0% } - light.addressable_set: { id: status_led, red: 0%, green: 0%, blue: 0% }
- delay: 0.5s - delay: 0.5s
- if: # return LED to switch state before - if: # return LED to old state before blinking
condition: condition:
switch.is_on: mlock_${name_of_board}_switch switch.is_on: mlock_${name_of_board}_switch
then: then:
@ -151,10 +153,6 @@ switch:
name: "Relais Output" name: "Relais Output"
id: mlock_${name_of_board}_switch id: mlock_${name_of_board}_switch
internal: true # hide from Homeassistant, so no one can turn it on without Tag-Scanning internal: true # hide from Homeassistant, so no one can turn it on without Tag-Scanning
on_turn_on:
- light.addressable_set: { id: status_led, red: 0%, green: 100%, blue: 0% }
on_turn_off:
- light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% }
binary_sensor: binary_sensor:
# sensor input for Turning Device off # sensor input for Turning Device off
@ -166,7 +164,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.addressable_set: { 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
@ -183,7 +181,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.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% }
light: light:
- platform: neopixelbus - platform: neopixelbus