My "restart cam when becoming unavailable" automation does not work...help

Hello all…

I have a somewhat flaky ip cam…that needs to be restarted once in a while…
So i thought i create an automation that checks if cam is having status “unavailable” and restarts it via “smart” outlet.
BUT…for some reason, my automation doesnt see the status or doesnt care…
Can anyone take a look and let me know what part i am missing?!

alias: Switch_Restart_BackyardCam
description: ""
triggers:
  - entity_id:
      - camera.backyard_cam
    for:
      hours: 0
      minutes: 0
      seconds: 30
    trigger: state
    attribute: Unavailable
conditions: []
actions:
  - type: turn_off
    device_id: 16ca6cd625032cf41316c62764c5bb16
    entity_id: 5c3122452470b3d17e59fa16b3dcf889
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - type: turn_on
    device_id: 16ca6cd625032cf41316c62764c5bb16
    entity_id: 5c3122452470b3d17e59fa16b3dcf889
    domain: switch
mode: single

Just checking:
Are you sure it’s an attribute that shows the camera unavailable and not the state itself?
And is it ‘Unavailable’ or ‘nnavailable’?

Ohhhh, that question might have solved my gordig knot.
It is a state…just checked…
And it is lower case unavailable

Glad to see that the stae makes more sense than my typing :confused:

Did you get it to work?

Unfortunately my changes to state did nothing
Is there a state check that does not require a change from something to something? Just if state is xyz than do bla bla?
Cause the code as it is rught now is looking a for a change from to unavailable, but the from stste can be a list of things and not just available.

Thx alot

Two options, I guess:

  1. Maybe using a ‘From’ definition in the trigger helps (e.g. from: idle or from: recording) to: unavailable helps - not sure, though, what the right status might be or if you’d need to use more than one trigger to capture all possibilities

  2. Check with a time pattern trigger, if the state is unavailable every 5 or 10 minutes - and if the camera is unavailable run the switch off/switch on action.

I have a camera that falls off now & then and I just do a switch off/on routine every night at e.g. 3:33AM - this has worked well for me so far and keeps me from checking every 5min.

Just did the rom part and will keep you posted…just not sure when it is going to happen next…or even why it does it…but already

Ok, day two and several camera flaws and still not automation trigger…
awkward…found in yaml view that it had the unavailable in “” with a space behind it:
"unavailable " but no change since

Hmmm - what does {{ states('camera.backyard_cam') }}SpaceOrNoSpace show in the Developer Tools - Template?

Right not it says “recording”

And now it says “unavailable”

Your trigger in the first post is all wrong. It is setup to monitor any changes to an attribute with name/key unavailable, rather than the state when its value changes to unavailable.

triggers:
  - trigger: state
    entity_id: camera.backyard_cam
    to: unavailable
    for:
      seconds: 30
2 Likes

Yes. Time. Here is an automation that I have that turns off power to a heated doormat if there has been no snow falling for 30 minutes.

alias: Turn off switch when no snow is detected
description: The Zooz outdoor switch is controlling the heated snow mat on the deck.
triggers:
  - minutes: /1
    trigger: time_pattern
conditions:
  - condition: template
    value_template: |
      {{ states('sensor.openweathermap_snow') | float < 0.9 and 
         (now() - states.sensor.openweathermap_snow.last_changed).total_seconds() > 1800 }}
actions:
  - target:
      entity_id: switch.zooz_outdoor_switch
    action: switch.turn_off
    data: {}
mode: single

The ‘SpaceOrNoSpace’ part was specifically put there to flush out any potential characters between the ‘state’ and the first ‘S’ :confused:

Try to put the ‘unavailable’ or ‘recording’ - whatever current state it’s supposedly in - as a condition and then test it using the Automation GUI Test functionality to verify it’s picking up the correct string.

image

You’ll either get a green or an orange band at the top of the condition box.

Ohhh…i see what that does/did…
Change dit to that and all the sudden i am even able to select from the possible states…
Thx alot…that was the winning ticket…i hope…haven’t seen it working yet, but it looks promising

I was looking everywhere…where do you get the test button?

Just click on the 3 dots below the question mark


Not in my world, but it is working niw, so thx alot anyway

You cannot test a trigger from the visual editor, only a condition.