How to test for non-functioning addon?

I know not many of you use Mochad to control old X10 devices but I was hoping you might be able to give me a suggestion on how to test if Mochad isn’t running properly. Unfortunately this is happening more frequently for some reason that I don’t understand.

When I look at my dashboard, I see that the devices are unavailable.
NotAvailable

The first thing I tried was to create an automation to test if Mochad is running.

- id: '1696112398023'
  alias: Restart Mochad if not running
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.mochad_running
    from: 'on'
    to: 'off'
  - platform: state
    entity_id:
    - binary_sensor.mochad_running
    from: 'on'
    to: unavailable
  condition: []
  action:
  - service: hassio.addon_stop
    data:
      addon: 185c312f_mochad
  - delay:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
  - service: hassio.addon_start
    data:
      addon: 185c312f_mochad
  mode: single

But that didn’t work because Mochad still thinks it’s running:
MochadRunning

Then I created an automation to check if three switches were unavailable. If so, I stop and restart Mochad.

- id: '1694801523246'
  alias: Mochad availability
  description: Check every 15 minutes if X10 devices are available
  trigger:
  - platform: time_pattern
    minutes: /15
  condition: []
  action:
  - if:
    - condition: state
      entity_id: switch.living_room_led_left
      state: unavailable
    - condition: and
      conditions:
      - condition: state
        entity_id: light.master_ceiling_light
        state: unavailable
    - condition: and
      conditions:
      - condition: state
        entity_id: switch.media_tv_lights
        state: unavailable
    then:
    - service: hassio.addon_stop
      data:
        addon: 185c312f_mochad
    - delay:
        hours: 0
        minutes: 0
        seconds: 30
        milliseconds: 0
    - service: hassio.addon_start
      data:
        addon: 185c312f_mochad
  mode: single

But that automation fails because it can’t find the entities.
FailedAutomation

So I need some help. What else can I test for?
The addon thinks it is running (green dot) when I look at the addon screen but isn’t using any CPU or RAM.
Any suggestions would be greatly appreciated!

What if you replace

with

 state: unknown

I got real excited when I saw your post @francisp but unfortunately no, this didn’t work. Thanks and if you have any other suggestions, I’m all ears.

You have to check if the entity exist instead.
Not really sure how it is done in HA though.

I think this might work. We’ll see as soon as Mochad goes south again. I created a template and it says “on” so I’m keeping my fingers crossed.Thanks for the idea @WallyR

{{ states('switch.living_room_led_left') is defined }}

The Mochad integration built into HA, and the Mochad server add-on are two separate programs and either one could be screwing up. I don’t normally run HA on a Pi, but I loaded HA on a Pi3b(1GB ram) and Mochad add-on shows 0% CPU and 0.5% RAM when it is working fine. My guess is that the Mochad server add-on is working, and it is the Mochad integration built into HA that is screwing up for you.

When it screws up, you can access the Mochad server add-on from another computer to see if it is working. For testing, I use PuTTY from ( http://putty.org) and telnet to the Mochad server using its IP address and port 1099. All the x10 activity shows up in the PuTTY output, and you can control lights by entering PL A10 ON or PL A10 OFF, where A10 is the house code and unit number.

{{ states('switch.living_room_led_left') is defined }}

It took a while for the failure scenario to occur again but this did NOT work.

Thanks @jeffs555 for the explanation - this helps a lot. Sorry I didn’t see your response right away.

I don’t totally understand how I would be using PuTTY. I understand that I can control lights using it but how am I testing for failure?

I think the has_value function/filter is what you’re looking for.

condition: template
value_template: "{{ has_value('switch.living_room_led_left') }}"

Yes @jazzyisj that is showing false and I have not restarted Mochad to rectify the problem so this looks like it might be the trigger I need to fix this problem. I’ll put this test in and send a text to myself when it’s triggered. Will let you know.

Thank you!

That condition will prevent the automation from running and causing an error but it won’t tell you something is wrong (unless you do an if/then/else using that condition in the action and do a notification in there somehow and even then it won’t be until the automation is triggered.)

You can create a template sensor that can be used to notify you as soon as your entities go unknown or unavailable. You can limit it to just monitor the integration you’re having a problem with.

If your integration is acting up regularly and restarting the addon is the fix, you can also automate restarting the addon instead of starting and stopping it.

@jazzyisj I just set up an automation (if/then/else) and it did stop and restart Mochad and fixed all of the X10 devices. YEA! Thank you.

No sweat. Sorry it took me so long to find your thread :grinning_face_with_smiling_eyes: