I have made 2 scripts where I was hoping to use the data from one script to another. But that seems to be failing / not getting it to work.
Hopefully you guys can help me out.
Or point me in a nicer solution of course
I have this script which checks who is at the door with the help of double take:
deurbel_persoon_check:
description: "Check who is at the front door"
sequence:
variables:
person_detect: >-
{% set time = as_timestamp(now()) %}
{% set rik = state_attr('sensor.double_take_rik', 'timestamp') %}
{% set amy = state_attr('sensor.double_take_amy', 'timestamp') %}
{% set max = state_attr('sensor.double_take_max', 'timestamp') %}
{% set sander = state_attr('sensor.double_take_sander', 'timestamp') %}
{% set sandra = state_attr('sensor.double_take_sandra', 'timestamp') %}
{% set postbode = state_attr('sensor.double_take_postbode', 'timestamp') %}
{% if (((as_timestamp(rik)) - time) | int >= -30 and (( time - as_timestamp(rik))) | int <= 30 ) %}
Rik staat bij de voordeur
{% elif (((as_timestamp(amy)) - time) | int >= -30 and (( time - as_timestamp(amy))) | int <= 30 ) %}
Amy staat bij de voordeur
{% elif (((as_timestamp(max)) - time) | int >= -30 and (( time - as_timestamp(max))) | int <= 30 ) %}
Max staat bij de voordeur
{% elif (((as_timestamp(sander)) - time) | int >= -30 and (( time - as_timestamp(sander))) | int <= 30 ) %}
Sander staat bij de voordeur
{% elif (((as_timestamp(sandra)) - time) | int >= -30 and (( time - as_timestamp(sandra))) | int <= 30 ) %}
Sandra staat bij de voordeur
{% elif (((as_timestamp(postbode)) - time) | int >= -30 and (( time - as_timestamp(postbode))) | int <= 30 ) %}
De postbode staat bij de voordeur.
{% else %}
Er staat iemand bij de voordeur nogsteeds
{% endif %}
And I have another one for controlling the google home speaker where I want to use the found text in the above script to tell who is at the door.
Bonus is that I can also use this script other messages, laundry finished ,3dprinter finished ,etc
huiskamer_notify:
description: "Send a TTS to all google nest devices"
fields:
message:
description: "The message content"
example: "The light is on!"
sequence:
# Set volume to 50 procent
- action: media_player.volume_set
data:
entity_id: media_player.huiskamer
volume_level: '0.5'
# Send tts to google speakers
- action: tts.speak
data:
message: "{{ message }}"
media_player_entity_id: media_player.huiskamer
language: nl
target:
entity_id: tts.google_nl_com
# Delay for 10 seconds
- delay: "00:00:10"
# Set volume back to 40 procent
- action: media_player.volume_set
data:
entity_id: media_player.huiskamer
volume_level: '0.4'
but for the usage of the doorbell, I kick off both the scripts after the doorbell has been pressed
doorbell_audio:
sequence:
- action: script.deurbel_persoon_check
- action: script.huiskamer_notify
data:
message: "{{ person_detect }}"
I was than hoping the variable person_detect would have been passed through.
But looking at the logs and listening to the google home speaker it doesnt seem to like it this way…
Main reason for asking this is that I now have the first script ( checking who is at the door template) in multiple message parts.
This feel like it can be done more nice and on 1 spot for instance ( in a script ).
2025-06-24 22:14:38.139 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'person_detect' is undefined when rendering '{{ person_detect }}'