Greetings.
I have a question how to make a continuous condition control. There is a switch UPS_Charge
in the off state, a closed loop must be spinning interrupted by external influences. This works, the loop is exited by the action of the virtual key sw_manual_auto
. But when the impact is removed, I can’t return to the cycle. and you have to manually cock the switch
- switch.turn_on: UPS_Charge
- switch.turn_off: UPS_Charge
after that the cycle starts and runs.
Ideally, I need to start automation in the key not by on_turn_off
but by on_IS_off
?
#===============================================================================
# SWITCH
#===============================================================================
switch:
- platform: restart # Переключатель перезагрузки устройства
name: Restart ${devicename}
#-------------------------------------------------------------------------------
- platform: template
name: "Ручное управление"
id: sw_manual_auto
lambda: !lambda |-
if (id(sw_manual_auto).state)
return true;
else return false;
optimistic: true
# assumed_state: true
turn_on_action:
- logger.log: "Ручное управление"
- switch.turn_off: UPS_Charge
turn_off_action:
- logger.log: "Автоматическое управление"
- switch.turn_on: UPS_Charge
- switch.turn_off: UPS_Charge
#-------------------------------------------------------------------------------
- platform: gpio
icon: mdi:battery-arrow-up
pin: ${UPS_Charge}
name: UPS Заряд АКБ #Заряд АКБ ${devicename}
id: UPS_Charge
restore_mode:
ALWAYS_OFF
on_turn_off:
then:
- switch.turn_off: UPS_Charge
- delay: ${read}
- if:
condition:
and:
- lambda: 'return id(vadc).state < 24.2;' #${vol_charge};'
- switch.is_off: sw_manual_auto
- binary_sensor.is_on: line_230vac
then:
- switch.turn_on: UPS_Charge
- logger.log: "Цикл заряда!"
- delay: !lambda |-
if (id(line_230vac).state)
return ${interval_ms};
else return 0;
- switch.turn_off: UPS_Charge
- logger.log: "Цикл заряда выключен"
else:
- switch.turn_off: UPS_Charge
- logger.log: "Заряд в норме"
on_turn_on:
- logger.log: "Switch Turned On!"
#-------------------------------------------------------------------------------
- platform: gpio
icon: mdi:home-battery-outline # mdi:transmission-tower-off
pin: ${UPS_nDC_BAT}
name: UPS DC/BAT #nDC / АКБ ${devicename}
id: UPS_nDC_BAT
restore_mode:
ALWAYS_OFF
#===============================================================================
# BINARY SENSOR
#===============================================================================
binary_sensor:
- platform: gpio
device_class: power
icon: mdi:transmission-tower
pin:
number: ${line_230vac}
inverted: true
mode:
input: true
pullup: true
name: Line 230VAC
id: line_230vac
filters :
- delayed_on_off: 1000ms
on_press:
then:
- switch.turn_off: UPS_nDC_BAT
- switch.turn_on: UPS_Charge
- switch.turn_off: UPS_Charge
on_release:
then:
- switch.turn_on: UPS_nDC_BAT
- switch.turn_off: UPS_Charge
#-------------------------------------------------------------------------------
- platform: gpio
device_class: battery_charging
icon: mdi:battery-arrow-up
pin:
number: ${Charging}
inverted: true
mode:
input: true
pullup: true
name: Charging
filters:
- delayed_on: 100ms
#-------------------------------------------------------------------------------
- platform: gpio
device_class: battery
icon: mdi:battery-check
pin:
number: ${Charge_OK}
inverted: true
mode:
input: true
pullup: true
name: Charge OK
filters:
- delayed_on: 100ms
#-------------------------------------------------------------------------------
- platform: template
device_class: running
icon: mdi:refresh-circle
id: bat_over_current
name: АКБ overcurrent
lambda: |-
if (id(bat_current).state > 1.0) {
return true;
} else {
return false;
}
on_press:
then:
- logger.log:
format: "Ток потребления от АКБ - value %.1f"
args: [ 'id(bat_current).state' ]
# - switch.turn_off: UPS_Charge
on_release:
then:
- logger.log: "Ток потребления от АКБ - Норма"
#===============================================================================
# SENSOR
#===============================================================================
sensor:
- platform: wifi_signal
name: WiFi ${devicename}
update_interval: ${wifi_scan}
icon: mdi:wifi-check
#-------------------------------------------------------------------------------
- platform: adc
pin: ${adc}
name: "АКБ"
id: vadc
update_interval: ${adc_scan}
filters:
- multiply: 33.24 #32 # Rup-10k Rd-330
#-------------------------------------------------------------------------------
- platform: ina226
address: 0x40
shunt_resistance: 0.1 ohm
current:
name: "INA226 Current"
id: bat_current
power:
name: "INA226 Power"
bus_voltage:
name: "INA226 Bus Voltage"
shunt_voltage:
name: "INA226 Shunt Voltage"
max_current: 3.2A
update_interval: ${ina226_scan}