I often write a entity state (for example selection from a input_select) to a other input entity. To not create always a separate script I try a little universal script but not sure if this is a good option to do so and my script is ok:
I think you mistaken source and destination at the domain variable. Not source but destination gives the service. So I changed some thinks and get this:
script_universal_setinputvalue:
alias: 'Universal - Entity Zustand in Input Entity speichern'
mode: parallel
max: 10
max_exceeded: silent
fields:
source_entity_id:
name: Source Entity
description: Entity der Quelle.
example: 'input_select.is_sonosfavs'
required: true
selector:
entity:
dest_entity_id:
name: Desitination Entity
description: Entity in dem gespeichert werden soll.
example: 'input_text.it_sonosfavcurrent_allgemein'
required: true
selector:
entity:
sequence:
- variables:
dest_domain: >-
{{- dest_entity_id.split('.')[0] -}}
source_state: >-
{% set value = states(source_entity_id) | string %}
{% if dest_entity_id.split('.')[0] == 'input_boolean' %}
{% if value in ['on','an','ein','true','1'] %}
{% set value = 'on' %}
{% else %}
{% set value = 'off' %}
{% endif %}
{% endif %}
{{- value -}}
- choose:
- conditions:
- condition: template
value_template: >-
{{ dest_domain in ['input_text', 'input_number'] }}
sequence:
- service: '{{ dest_domain}}.set_value'
target:
entity_id: '{{ dest_entity_id }}'
data:
value: >-
{{- source_state -}}
- conditions:
- condition: template
value_template: >-
{{ dest_domain == 'input_boolean' }}
sequence:
- service: 'input_boolean.turn_{{ source_state }}'
target:
entity_id: '{{ dest_entity_id }}'
Happy to get your comments learning some advanced script technical.
Also, you may want to define a default for your Choose action in case you select a destination entity that isn’t covered. Something like:
default:
- service: persistent_notification.create
data:
message: >
A {{domain}} helper has been set as destination for
script.script_universal_setinputvalue.
No action exists to handle this helper type.
title: Script Error