deiger / Alarm

Code to connect and control alarms by PIMA.
GNU General Public License v3.0
16 stars 11 forks source link

Exit on `Not enough data`, `Garbage` and etc to prevent freezes #20

Closed ShonP40 closed 1 year ago

ShonP40 commented 1 year ago

I installed this project as an Home Assistant addon and noticed that every about 30-60 minutes, it would just freeze with a not enough data... error and never exit, resulting in HA's watchdog not detecting it as a crash & not restarting the addon.

This PR should resolve this issue completely by exiting when these errors occur, prompting watchdog to restart the addon.

(This should also resolve issue #9)

ShonP40 commented 1 year ago

As a temporary solution, people who encounter these freezes can also setup an automation that restarts the addon automatically

mqtt:
  binary_sensor:
    - name: PIMA Status
      state_topic: "alarm/status"
      icon: mdi:server
      value_template: '{{ value_json[''logged in''] }}'
      payload_off: true
      payload_on: false
      json_attributes_topic: "alarm/status"
      expire_after: 60
      device_class: problem
automation:
  - alias: 'PIMA: Restart on freeze'
    trigger:
    - platform: state
      entity_id:
      - binary_sensor.pima_status
      to: unavailable
    condition: []
    action:
    - service: hassio.addon_restart
      data:
        addon: {Replace with your addon ID}_pima
    mode: single
maorcc commented 1 year ago

I believe the above "workaround" (as you call it) actually works fine in some environments. 👍

maorcc commented 1 year ago

I've learned that the errors like "not enough data" may be related to the hardware used to communicate with Pima. Over the last two years, I've used the PIMA Alarm integration with three different TTL devices:

First, Raspberry PI Zero

The first was with a Raspberry PI Zero, that I installed inside the alarm box. It was running the Pima/Alarm service, and communicating with Home Assistant over the LAN via MQTT. image It worked fine but got the "not enough data" error every other week, so I added an automation, like the one @ShonP40 suggested above, to restart the Alarm service whenever it stopped working. This worked OK for me.

Second, a PL2303TA cable

After a year, I decided that I don't want to have a PI "computer" just as a connection to Pima, so I replaced it with a PL2303TA cable, and started running the Pima/Alarm as a HomeAssistant AddOn. image This device was working only for a few hours every time, until hanging. I had to reboot my Home Assistant's main Raspberry PI or physically disconnect and reconnect it to the USB connector in order to make it work again. It is a disappointment for me. There was a 2-3 celsius degrees increase in the Raspberry PI temperature whenever the PL2303TA is connected to it. I bought it here: https://www.aliexpress.com/item/32345829369.html

Third, a CH340G RS232 to TTL module

Per the recommendations on Tasmota forums for the CH340G, I replaced the PL2303TA with it.
image It is much better now. I've installed it a week ago. So far it didn't show any issues. I also do not see it impacting the PI's temperature. I bought it here: https://www.aliexpress.com/item/32761423124.html

ShonP40 commented 1 year ago

I'm currently using an FT232RL adapter that's plugged into an RPi 4, but I'm planning on connecting the PIMA system straight to the RPi's UART pins soon to keep it more compact.

maorcc commented 1 year ago

Cool!
I'd love to hear how well the AddOn works with the PI's UART. I didn't yet try.

ShonP40 commented 1 year ago

Ended up giving up on trying to use the RPi's UART because Home Assistant OS keeps resetting every config.txt change I add on reboot