Help needed. I want to reboot Raspberry Pi when entity disappears but fails

I’m using a curtain motor. It will disappear from the entity list once in a while but it will come back after I reboot Pi. I notice there is a message about it in the log:

You are using a custom component for cover.hassmart which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.

It could be the problem of the motor itself. The only way I can think of is to config an automation and reboot automatically. Since the entity has disappeared, I don’t know how to trigger an automation from it, but I try the following template in the developer tools section and is appears as “True”:

{{ states(‘cover.hassmart_192_168_2_76’) == ‘unknown’ }}

So I config the automation below but it never triggers.

  • alias: reboot_at_curtain_motor_lost
    hide_entity: false
    initial_state: on
    trigger:
    platform: template
    value_template: “{{ states(‘cover.hassmart_192_168_2_76’) == ‘unknown’ }}”
    action:
    • service: shell_command.reboot_pi

The service “shell_command.reboot_pi” is a shell command I put in the configuration.yaml

> shell_command:
>    reboot_pi: '/usr/bin/sudo /sbin/shutdown -r now'

I can manually trigger the automation “reboot_at_curtain_motor_lost” and Pi do reboot. But I can’t figure out why I can’t trigger.

Could you guys please help me, What is wrong with my configuration? Is there any better ways to trigger the automation? Thanks very much!!

Unfortunately your formatting doesn’t allow us to see the automation correctly. Please have a look at the sticky post.

I’d expect though that the following trigger would work:

trigger:
  platform: state
  entity_id: cover.hassmart_192_168_2_76
  to: "unknown"
  for: '00:02:00'

That should require it to be unknown for two minutes before triggering, to avoid false restarts.

You can ignore this message in the log. It appears on every restart for every custom component, it’s just a warning that this custom component might cause problems. You could disable it if you want to.

Instead of making a workaround, I would rather try to find out why your Pi disappears from the entity list, but to each his own.

Thanks very much for you prompt reply, Tinkerer. I’ve tried you way. But it couldn’t trigger either. I think it is because the entity “cover.hassmart_192_168_2_76” had disappeared from the entity list and therefore, its state didn’t exist, so it won’t trigger the automation. That’s why I try the template trigger. Even though the entity “cover.hassmart_192_168_2_76” had disappeared, but when I tried to get the state of it by using template, it returned “True”. I just couldn’t figure out why the automation couldn’t be triggered when the condition was satisfied.

My bad for the formatting. I’m not quite familiar with this editor. Below is the automation I tried to make it work:

- alias: reboot_at_curtain_motor_lost 
  hide_entity: false
  initial_state: on
  trigger:
    platform: template
    value_template: "{{ states('cover.hassmart_192_168_2_76') == 'unknown' }}"
  action: 
    - service: shell_command.reboot_pi

Thanks for your reply, Burningstone. I noticed the message in the log long before the problem happened. Since the program is provided by the motor vendor, and I’m not familiar with python, there is nothing I can do about it. So I just ignore it.
The only way I can think of now is to reboot manually when the curtain motor disappears from the entity list. This is tiresome. That’s why I try to make it automatically.

1 Like

What does this show when you put it in the template editor?

It said “True”. That’s why I couldn’t figure out why the automation couldn’t be triggered. Please see the snapshot below.

and after a reboot, when the sensor is working?

After reboot, It appears back in the entities list and works well.
At this time, when I put
{{ states(‘cover.hassmart_192_168_2_76’) == ‘unknown’ }}
in the template editor, it shows “False”.

Perhaps try using the example code here

Many thanks for your help, Nickrout. I’m now using the example code as you suggested. Since it’s from the official document, I think it will work. I’ll update if it didn’t. Thanks again!