Help With Door Alert Automation

Please could somebody look at this automation for me, it used to work until recently. Uses presence detection with a xiaomi door sensor. Something must have changed that has stopped it from working. If I manually change the states it fires as expected. Many thanks.

- alias: Door alerts
  trigger:
    platform: state
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_25ff2e02_on_off
  condition:
    condition: and
    conditions:
    - condition: template
      value_template: '{{ trigger.from_state.state == ''on'' or trigger.from_state.state
        == ''off'' or trigger.from_state.state == ''open'' or trigger.from_state.state
        == ''closed'' }}'
  action:
  - service: tts.google_translate_say
    data_template:
      entity_id: media_player.living_room_home_mini, media_player.dining_room_home_mini
      message: "{% if (trigger.entity_id == 'binary_sensor.lumi_lumi_sensor_magnet_aq2_25ff2e02_on_off')\
        \ and trigger.from_state.state == 'on' and trigger.to_state.state == 'off'\
        \ %}\n  {% for state in states.person if (state.state == 'home' and ((as_timestamp(now())\
        \ - as_timestamp(state.last_changed)) / 60) < 5) %}\n    {%- if loop.first\
        \ %}{{ [ \"Hello, welcome back,\",\"Great to see you again, \", \"We missed\
        \ you,\",\"Back so soon,\",\"Nice of you to drop by,\",\"Watts that smell.\
        \ It must be,\",\"Oh no.It's,\",\"Hooray! It's \",\"Watts that coming over\
        \ the hill. Is it a monster. Is it,\",\"Is it a bird, is it a plane, it’s\
        \ super,\"] | random }}\n      {% elif loop.last %} and\n      {% else %},\n\
        \    {% endif -%}\n    {{ state.name }}\n  {%- endfor %}\n{% endif %}\n"

What do you mean by “manually changing the states”? On the states page you enter a different state? If that’s what you mean I would say the automation itself is working and if anything your sensor is not actually updating. If you have the states page up and you open and close the door or whatever (not sure what type of sensor it is) … does the state change?
Also is there really multiple states it could be or is it just on/off on the dev tools>states page

1 Like

Sorry for the delay in replying! Turned out it was as simple as the door sensor not being on the network! Rookie mistake!