Use new switch.on_state

This commit is contained in:
Edward Firmo
2025-08-09 14:46:14 +02:00
parent aae3eaa204
commit fc135875c5
2 changed files with 32 additions and 41 deletions

View File

@@ -1526,20 +1526,18 @@ switch:
optimistic: true optimistic: true
internal: false internal: false
entity_category: config entity_category: config
on_turn_on: on_state:
then: then:
- binary_sensor.template.publish: - binary_sensor.template.publish:
id: bs_pending_restart id: bs_pending_restart
state: true state: true
- lambda: |- - if:
id(relay_switches_packed) |= 0x01; // Set bit 0 condition:
on_turn_off: - lambda: return x; // Turned on?
then: then:
- binary_sensor.template.publish: - lambda: id(relay_switches_packed) |= 0x01; // Set bit 0
id: bs_pending_restart else:
state: true - lambda: id(relay_switches_packed) &= ~0x01; // Clear bit 0
- lambda: |-
id(relay_switches_packed) &= ~0x01; // Clear bit 0
- id: sw_relay_1 - id: sw_relay_1
name: Relay 1 name: Relay 1
@@ -1547,103 +1545,99 @@ switch:
platform: output platform: output
restore_mode: ${RELAYS_SWITCH_RESTORE_MODE} restore_mode: ${RELAYS_SWITCH_RESTORE_MODE}
internal: true internal: true
on_turn_on: on_state:
then: then:
- script.execute: show_relay_status - script.execute: show_relay_status
on_turn_on:
then:
- if: - if:
condition: condition:
- light.is_off: light_output_1 - light.is_off: light_output_1
then: then:
light.turn_on: light_output_1 light.turn_on: light_output_1
- lambda: |- - lambda: id(relay_switches_packed) |= 0x02; // Set bit 1
id(relay_switches_packed) |= 0x02; // Set bit 1
on_turn_off: on_turn_off:
then: then:
- script.execute: show_relay_status
- if: - if:
condition: condition:
- light.is_on: light_output_1 - light.is_on: light_output_1
then: then:
- light.turn_off: light_output_1 - light.turn_off: light_output_1
- lambda: |- - lambda: id(relay_switches_packed) &= ~0x02; // Clear bit 1
id(relay_switches_packed) &= ~0x02; // Clear bit 1
- id: sw_relay_2 - id: sw_relay_2
name: Relay 2 name: Relay 2
output: output_relay_2 output: output_relay_2
platform: output platform: output
restore_mode: ${RELAYS_SWITCH_RESTORE_MODE} restore_mode: ${RELAYS_SWITCH_RESTORE_MODE}
internal: true internal: true
on_turn_on: on_state:
then: then:
- script.execute: show_relay_status - script.execute: show_relay_status
on_turn_on:
then:
- if: - if:
condition: condition:
- light.is_off: light_output_2 - light.is_off: light_output_2
then: then:
light.turn_on: light_output_2 light.turn_on: light_output_2
- lambda: |- - lambda: id(relay_switches_packed) |= 0x04; // Set bit 2
id(relay_switches_packed) |= 0x04; // Set bit 2
on_turn_off: on_turn_off:
then: then:
- script.execute: show_relay_status
- if: - if:
condition: condition:
- light.is_on: light_output_2 - light.is_on: light_output_2
then: then:
- light.turn_off: light_output_2 - light.turn_off: light_output_2
- lambda: |- - lambda: id(relay_switches_packed) &= ~0x04; // Clear bit 2
id(relay_switches_packed) &= ~0x04; // Clear bit 2
- id: sw_relay_3 - id: sw_relay_3
name: Relay 3 name: Relay 3
output: output_relay_3 output: output_relay_3
platform: output platform: output
restore_mode: ${RELAYS_SWITCH_RESTORE_MODE} restore_mode: ${RELAYS_SWITCH_RESTORE_MODE}
internal: true internal: true
on_turn_on: on_state:
then: then:
- script.execute: show_relay_status - script.execute: show_relay_status
on_turn_on:
then:
- if: - if:
condition: condition:
- light.is_off: light_output_3 - light.is_off: light_output_3
then: then:
- light.turn_on: light_output_3 - light.turn_on: light_output_3
- lambda: |- - lambda: id(relay_switches_packed) |= 0x08; // Set bit 3
id(relay_switches_packed) |= 0x08; // Set bit 3
on_turn_off: on_turn_off:
then: then:
- script.execute: show_relay_status
- if: - if:
condition: condition:
- light.is_on: light_output_3 - light.is_on: light_output_3
then: then:
- light.turn_off: light_output_3 - light.turn_off: light_output_3
- lambda: |- - lambda: id(relay_switches_packed) &= ~0x08; // Clear bit 3
id(relay_switches_packed) &= ~0x08; // Clear bit 3
- id: sw_relay_4 - id: sw_relay_4
name: Relay 4 name: Relay 4
output: output_relay_4 output: output_relay_4
platform: output platform: output
restore_mode: ${RELAYS_SWITCH_RESTORE_MODE} restore_mode: ${RELAYS_SWITCH_RESTORE_MODE}
internal: true internal: true
on_turn_on: on_state:
then: then:
- script.execute: show_relay_status - script.execute: show_relay_status
on_turn_on:
then:
- if: - if:
condition: condition:
- light.is_off: light_output_4 - light.is_off: light_output_4
then: then:
- light.turn_on: light_output_4 - light.turn_on: light_output_4
- lambda: |- - lambda: id(relay_switches_packed) |= 0x10; // Set bit 4
id(relay_switches_packed) |= 0x10; // Set bit 4
on_turn_off: on_turn_off:
then: then:
- script.execute: show_relay_status
- if: - if:
condition: condition:
- light.is_on: light_output_4 - light.is_on: light_output_4
then: then:
- light.turn_off: light_output_4 - light.turn_off: light_output_4
- lambda: |- - lambda: id(relay_switches_packed) &= ~0x10; // Clear bit 4
id(relay_switches_packed) &= ~0x10; // Clear bit 4
... ...

View File

@@ -151,20 +151,17 @@ switch:
pin: GPIO21 pin: GPIO21
restore_mode: ALWAYS_OFF restore_mode: ALWAYS_OFF
internal: true internal: true
on_turn_on: on_state:
then: then:
- binary_sensor.template.publish: - binary_sensor.template.publish:
id: bs_vibrating id: bs_vibrating
state: ON # yamllint disable-line rule:truthy state: !lambda return x;
on_turn_on:
then:
- delay: ${vibration_max_duration} - delay: ${vibration_max_duration}
- if: - if:
condition: condition:
switch.is_on: sw_vibration_motor switch.is_on: sw_vibration_motor
then: then:
- switch.turn_off: sw_vibration_motor - switch.turn_off: sw_vibration_motor
on_turn_off:
then:
- binary_sensor.template.publish:
id: bs_vibrating
state: OFF # yamllint disable-line rule:truthy
... ...