From 629bfbed9e77fcdf073bb1b220501d73f1bc60b9 Mon Sep 17 00:00:00 2001 From: neri Date: Sat, 2 Mar 2024 02:16:31 +0100 Subject: [PATCH] wip: reduce code --- mlock-common.yaml | 43 ++++++++++--------------------------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/mlock-common.yaml b/mlock-common.yaml index 8c84254..1db4a6b 100644 --- a/mlock-common.yaml +++ b/mlock-common.yaml @@ -115,19 +115,13 @@ rc522_spi: then: - lambda: |- json::parse_json(id(http_request_data).get_string(), [](JsonObject root) { - int foobar = 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; - } + id(may_switch_output) = root["data"]["mlock-$name_of_board"]; }); - if: condition: lambda: 'return id(may_switch_output);' then: - - light.addressable_set: { id: status_led, red: 0%, green: 100%, blue: 0% } + - switch.turn_on: mlock_${name_of_board}_switch else: - repeat: count: 3 @@ -136,13 +130,6 @@ rc522_spi: - delay: 0.1s - light.addressable_set: { id: status_led, red: 0%, green: 0%, blue: 0% } - 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 - repeat: count: 3 @@ -151,15 +138,13 @@ rc522_spi: - delay: 0.5s - light.addressable_set: { id: status_led, red: 0%, green: 0%, blue: 0% } - delay: 0.5s - - 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% } - - + - 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% } # switch component for the output state switch: @@ -167,7 +152,7 @@ switch: pin: D1 name: "Relais Output" 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 binary_sensor: # sensor input for Turning Device off @@ -188,7 +173,6 @@ binary_sensor: publish_initial_state: true lambda: |- return id(mlock_${name_of_board}_switch).state; - # a button element for Homeassistant UI to allow turning off button: @@ -199,8 +183,6 @@ button: - switch.turn_off: mlock_${name_of_board}_switch - light.addressable_set: { id: status_led, red: 100%, green: 0%, blue: 0% } - - light: - platform: neopixelbus type: GRB @@ -211,8 +193,3 @@ light: num_leds: 1 internal: true - - - - - \ No newline at end of file