I you only want the automation to process four specific persons, here’s how it can be done with Counted Repeat.
alias: MQTT Presence Initialise
description: Respond with data when the BlinktPi Initialises
trigger:
- platform: mqtt
topic: blinktpi/response
payload: Initialise
condition: []
action:
- variables:
persons: [ 'darren', 'h', 'a', 'k' ]
- repeat:
count: '{{ persons | count }}'
sequence:
- variables:
person: '{{ persons[repeat.index - 1] }}'
- service: mqtt.publish
data:
topic: blinktpi/presence
payload_template: >
{ "person": "{{ person }}","status": "{{ states('person.' ~ person) }}" }
mode: single