Help needed for automation in Manual Alarm

I need help with automation that activates the alarm.
Currently I have a NodeMCU with Tasmota connected to the Tecnoalarm alarm control panel.
The NodeMCU reads the status of the Alarm, and if the alarm is activated or deactivated it turns telemetry to ON, or OFF
in this way, through MQTT, Hassio when reading the telemetry of the NodeMCU , through the example automation:

- alias: ‘Activate  Alarme Totale
  initial_state: 'on'
  triggers:
  - platform: state
    entity_id: switch.state_alarm_total
    to: 'on'
  condition:
  - condition: state
    entity_id: alarm_control_panel.allarme
    state: disarmed
  action:
  - service: alarm_control_panel.alarm_arm_away
    data:
      entity_id: alarm_control_panel.allarme
      code:! secret alarm_code

the status of the Manual Alarm change to Arm Away, so I can manage relative automation of Hassio, active only on activated alarm.
The problem arises when the NodeMCU loses connection on MQTT …
the MQTT log says: Client NodeMCU1 has exceeded timeout, disconnecting) and then reconnects, probably for bad connection or other problems
this causes the Arm Away to be disabled,
is there a way to modify the automation so that it reads the status of the NodeMCU and not its change from OFF to ON?

I don’t really understand what you are doing with the nodeMCU but there is a problem with this:

  action:
  - service: alarm_control_panel.alarm_arm_away
    date:   ####<---- should be "data:"

you’re right, google translator changed it… sorry: it’s indeed “data”

Change your trigger to this:

- alias: ‘Activate  Alarme Totale
  initial_state: 'on'
  triggers:
  - platform: state
    entity_id: switch.state_alarm_total
    from: 'off'
    to: 'on'

This will prevent the automation firing when going from unknown to on.

Do the same for your disarm automation.

- alias: ‘Disattiva Allarme Programma Totale’
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id: switch.stato_allarme_totale
    to: 'off'
  action:
  - service: alarm_control_panel.alarm_disarm
    data:
      entity_id: alarm_control_panel.allarme
      code: !secret alarm_code

I have three automations to activate the three alarm states (the NodeMCU is connected to 3 outputs of the alarm) :

alarm_arm_night
alarm_arm_home
alarm_arm_away

and three automation to switch them off

I will try, meanwhile, thank you very much for the advice

Hi Gianluca, I really interested to your project. Could I have some details (maybe in a private conversation if you prefer) about your physical interface to the tecnoalarm box? I have a Tp8 and I’m searching for a way to connect it with HA. Thank you in advance