Automation to turn off a switch when when the state of another switch goes offline or becomes unavailable

I wanted to create an automation for 2 switches. Switch 1 turns on my water pump, and switch 2 turns on a light when the water level of my tank goes 1/4 level already. I tried creating in automations. The action part of the automation works if i try to test it with run action but the trigger part doesn’t work. Anyone can help me out? Big thanks to everyone.


type or paste code here

platform: state
entity_id:
  - switch.sonoff_1001f59072
for:
  hours: 0
  minutes: 0
  seconds: 3
to: unavailable

type: turn_off
device_id: 497d****bba6b9a0dc19552***654
entity_id: switch.sonoff_1001f54478
domain: switch

When sonoff_1001f59072 goes unavailable, what does the trace look like?

Going through the logs.This is what I can see:
Yellow Light became unavailable
4:46:06 PM - 6 hours ago

But the automation doesn’t trigger. Instead on the trace it looks like this only.
This node was not executed and so no further trace information is available.

Under step config it shows:
platform: state
entity_id:

  • switch.sonoff_1001f59072
    for:
    hours: 0
    minutes: 0
    seconds: 3
    to: unavailable

For testing purposes, you can temporarily “force” the switch’s value to be unavailable.

  1. Go to Developer Tools > States

  2. Find switch.sonoff_1001f59072 in the list and click it.

  3. Scroll to the top of the page where all of the switch’s properties are displayed in a form.

  4. Take note of its current State value (perhaps make a copy of it). It should currently be on or off for the test to work.

  5. Change the value to unavailable.

  6. Click the Set State button.

  7. After 3 seconds, the automation’s State Trigger should trigger.

Use the same technique to set the switch’s value back to its original state.