Automation State trigger triggers also by an entity-state "unavailable"

I’ve setup the following automation:

alias: Solar Battery Discharge/Charge Correction
description: Solar Battery Discharge/Charge Correction
trigger:
  - platform: state
    entity_id: sensor.inverter_efficiency_loss_daily
    not_from:
      - unknown
      - unavailable
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ states('sensor.battery_charge_discharge_power')|float(0) >= 0
              }}
        sequence:
          - service: input_number.set_value
            data:
              value: >
                {% set total_loss =
                states('sensor.inverter_efficiency_loss_daily')|float(0) %} {%
                set bat_out_loss =
                states('input_number.battery_discharge_loss')|float(0)
                %}          {{ total_loss - bat_out_loss }}
            target:
              entity_id: input_number.battery_charge_loss
      - conditions:
          - condition: template
            value_template: "{{ states('sensor.battery_charge_discharge_power')|float(0) < 0 }}"
        sequence:
          - service: input_number.set_value
            data:
              value: >
                {% set total_loss =
                states('sensor.inverter_efficiency_loss_daily')|float(0) %} {%
                set bat_in_loss =
                states('input_number.battery_charge_loss')|float(0) %}         
                {{ total_loss - bat_in_loss }}
            target:
              entity_id: input_number.battery_discharge_loss
mode: single

If I reload the related Integration the state from sensor.inverter_efficiency_loss_daily is going into “unavailable” and therefore below trigger should not be triggered

trigger:
  - platform: state
    entity_id: sensor.inverter_efficiency_loss_daily
    not_from:
      - unknown
      - unavailable

But the first sequence is fired and is disturbing my input_number.battery_discharge_loss.

Before the reload:

During the reload:

Any ideas in which way to prevend?

  - platform: state
    entity_id: sensor.inverter_efficiency_loss_daily
    not_from:
      - unknown
      - unavailable
    not_to:
      - unknown
      - unavailable
1 Like

Amazing - It works now as expected!

Many thanks!!!

1 Like