Problem with python scripts in HA

I am new to home automation and HA. I would like to apologize in advance, I do not know English very well and therefore there may be errors in the syntax

I am using Raspberry Pi 5, HAos and Zigbee2MQTT

I am trying to use python scripts to control my home heating. For the test, I turn my relay on and off 10 times in a row. After 3 cycles of turning on and off, my Pi5 reboots. I tried to catch the error by which it (Pi5) reboots, but I did not see any errors in the logs. Initially, I thought that the problem was that I was using Appdaemon, but after using the HomeAssistant-API package, nothing changed. Below is the code that I used. I would be very grateful if you could help me, because using built-in automation is very inconvenient for me

I cut the main code to leave only functions related to relay switching

Code used on Appdaemon:

 import appdaemon.plugins.hass.hassapi as hass

 class TelegramBot(hass.Hass):
    def initialize(self):
       self.turn_on("switch.0x54ef441000b722b2_l1")

    def _clb_button_relay_off(self, target_id, paramdict):
       self._turn_off("switch.0x54ef441000b722b2_l1")

Code used with HomeAssistant-API:

 from homeassistant_api import Client

 URL = 'http://homeassistant:8123/api'
 TOKEN = ' '

 client = Client(URL, TOKEN)

 relay = client.get_domain('switch')
 relay.turn_on(entity_id='switch.0x54ef441000b722b2_l1')
 relay.turn_off(entity_id='switch.0x54ef441000b722b2_l1')
1 Like