reduce code
This commit is contained in:
parent
bf8cfd182f
commit
aa73c8b4c6
|
@ -115,19 +115,13 @@ rc522_spi:
|
||||||
then:
|
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) {
|
||||||
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 +130,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
|
||||||
|
@ -159,8 +146,6 @@ rc522_spi:
|
||||||
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:
|
||||||
- platform: gpio
|
- platform: gpio
|
||||||
|
@ -189,7 +174,6 @@ binary_sensor:
|
||||||
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:
|
||||||
- platform: template
|
- platform: template
|
||||||
|
@ -199,8 +183,6 @@ button:
|
||||||
- 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 +193,3 @@ light:
|
||||||
num_leds: 1
|
num_leds: 1
|
||||||
internal: true
|
internal: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue