Automation not triggered when device comes back on line

Hi, I need help on an automation where the trigger has occurred when another device was off line. When it comes back online in an “off” state the automation does not see the stat change.

How can I set an automation to compare a value and not act only when there is a change off state?

More details:
So scenario is two separate sensors, one is on a temp sensor. The other is smart switch that turns on a pump. This pump switch power is turned off overnight independently. So the pump switch status is not always available.
The automation is, if temp drops below 29 Deg for 10 mins and pump is off, turn on pump. What happens is if temp drops below 29 over night, when pump switch is not available it meets the condition, but as pump switch is off line it does not get the message to turn on.
When it comes online later because the state is not changing it wont trigger the event and turn on. If I play with the temp and go up and below the trigger 29 it will trigger the automation successfully.

How can I get an automation to either rescan that state is matching a value or instead an automation that has State changes its equal a text value of “open”?

I posted this question in Discord channel and suggestion was to use Away States but could not understand how to use them in this case.
Here is the config

alias: 'Solar ON < 29deg '
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.temp_state
    below: '29'
    for: '0:10:00'
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: switch.solar_pump
        state: 'off'
action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.solar_pump
mode: single

I am using MQTT and sonoff smartplug. HASIO v 2020.11.0

condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: switch.solar_pump
        state: 'on'
action:
  - wait_template: "{{ is_state('switch.solar_pump','off') }}"
  - service: switch.turn_on
    data: {}
    entity_id: switch.solar_pump

This requires that the switch isn’t on (so, off or unavailable). Then when the actions run it will wait for the switch to become off - if it’s already off there’s no wait.

Hi, this is a good option but its not always working. I have dev setup exactly the same as the production system except I am using a slightly different smart switch names.
Sometimes it works sometimes it does not. It seems to not work reliably when the device needs to turn off when powered up.
I have two automatons to turn on and off the pump.

alias: Turn Off Pump
description: ''
trigger:
  - platform: state
    entity_id: switch.smart_plug_valve
    from: 'on'
    to: 'off'
    for: '00:00:30'
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: switch.smart_plug_test
        state: 'off'
action:
  - wait_template: '{{ is_state(''switch.smart_plug_test'',''on'') }}'
  - service: switch.turn_off
    data: {}
    entity_id: switch.smart_plug_test
mode: restart

and to turn on

alias: Turn on Pump
description: ''
trigger:
  - platform: state
    entity_id: switch.smart_plug_valve
    from: 'off'
    to: 'on'
    for: '00:00:30'
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: switch.smart_plug_test
        state: 'on'
action:
  - wait_template: '{{ is_state(''switch.smart_plug_test'',''off'') }}'
  - service: switch.turn_on
    data: {}
    entity_id: switch.smart_plug_test
mode: restart

When I look at the logs it shows the following sequence;

  1. switch.smart_plug_test status = OFF
  2. switch.smart_plug_valve status = OFF
  3. I power off the switch.smart_plug_test switch physically
  4. switch.smart_plug_test status = unavailable
  5. switch.smart_plug_valve status = ON (I turn it on manually in HASSIO)
  6. wait 30 seconds
  7. switch.smart_plug_valve status triggers turn on pump
  8. I power back on switch.smart_plug_test switch (physically)
  9. it reports switch.smart_plug_test switch off (if does not then suddenly turn on)

when it does work its the same sequence but I see an extra step which causes it to work

10, switch.smart_plug_testturned on by “turn on pump”