Compare commits

...

2 Commits

Author SHA1 Message Date
neri 190bb2a9a2 try the impossible thing 2024-03-02 02:32:18 +01:00
neri aa73c8b4c6 reduce code 2024-03-02 02:31:58 +01:00
1 changed files with 17 additions and 38 deletions

View File

@ -92,7 +92,6 @@ 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:
@ -107,27 +106,20 @@ 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: 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(id(http_request_data).get_string(), [](JsonObject root) {
int foobar = root["data"]["mlock-$name_of_board"]; id(may_switch_output) = root["data"]["mlock-$name_of_board"];
if(foobar == 1) {
id(mlock_${name_of_board}_switch).turn_on();
id(may_switch_output) = 1;
} else {
id(may_switch_output) = 0;
}
}); });
- if: - if:
condition: condition:
lambda: 'return id(may_switch_output);' lambda: 'return id(may_switch_output);'
then: then:
- light.addressable_set: { id: status_led, red: 0%, green: 100%, blue: 0% } - switch.turn_on: mlock_${name_of_board}_switch
else: else:
- repeat: - repeat:
count: 3 count: 3
@ -136,13 +128,6 @@ rc522_spi:
- delay: 0.1s - delay: 0.1s
- 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.1s - delay: 0.1s
- if: # return LED to old state before blinking
condition:
switch.is_on: mlock_${name_of_board}_switch
then:
- light.addressable_set: { id: status_led, red: 0%, green: 100%, blue: 0% }
else:
- light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% }
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
@ -151,15 +136,13 @@ 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 old state before blinking - 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.addressable_set: { id: status_led, red: 0%, green: 100%, blue: 0% }
else: else:
- light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% } - light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% }
# switch component for the output state # switch component for the output state
switch: switch:
@ -167,7 +150,11 @@ switch:
pin: D1 pin: D1
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
@ -179,7 +166,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
@ -188,7 +175,6 @@ binary_sensor:
publish_initial_state: true publish_initial_state: true
lambda: |- lambda: |-
return id(mlock_${name_of_board}_switch).state; return id(mlock_${name_of_board}_switch).state;
# a button element for Homeassistant UI to allow turning off # a button element for Homeassistant UI to allow turning off
button: button:
@ -197,10 +183,8 @@ 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
type: GRB type: GRB
@ -211,8 +195,3 @@ light:
num_leds: 1 num_leds: 1
internal: true internal: true