Script with variables not working

I’ve seen a lot of post, but few real answers and none that solve my problem.
Anyway, passing allong variable seems not to work… but it’s almost exactly what is shown on home_ass.io

description: "test variables"
fields:
  title:
    description: variable1
  message: 
    description: variable2
  
sequence:
  - condition: state
    entity_id: input_boolean.automate_perm_greenrm
    state: 'on'
  - service: notify.persistent_notification
    data:
      title: " {{ title }} "
      message: "{{message}}"

The result is an empty persistent notification…but why??

How are you passing the variables to the script?

There are two methods. Which one you use depends on if the script is called directly as a service or by using the script.turn_on service.

So I endud up using the dev tools, made the script as shown, triggered it in place…no joy.
I was expection variable1 to be passed as title of the notification, 2 as the body/message.

I tried using the script.turn_on and the script.test_variables routes, in which case I get straight errors.

The script I logged above was my end of the line, the idea was to use a HA example to proof it would work, it didn’t.

Below is what I need.

alias: Verhoog Temperatuur
sequence:
  - service: climate.set_temperature
    data:
      temperature: "{{sensor}}"
    target:
      entity_id: "{{entity_id}}"
mode: single
icon: mdi:arrow-up-bold
service: script.verhoog_temperatuur
data:
  variables:
    sensor: {{ (((states('sensor.woonkmr_set_point')) | round(2) ) + ( 0.2 | float ) ) | round(1) }}
    entity_id: "climate.woonkamer"

You need " " around your template for the sensor value in your service call.

service: script.verhoog_temperatuur
data:
  variables:
    sensor: "{{ (states('sensor.woonkmr_set_point') | round(2) + 0.2) | round(1) }}"
    entity_id: "climate.woonkamer"

Without the quotes, your script is receiving a nonsense string instead of a numeric string.

Thanks guys!

Sorry, that was stupid indeed and I did have those in there, but out of frustration tried it without.
And subsequently posted that, sorry.

Anyway it still does not solve the problem…

- type: custom:mushroom-template-card
  primary: >-
    Nu: {{state_attr('climate.woonkamer', 'current_temperature')
    }}
  secondary: 'set: {{states(''sensor.woonkmr_set_point'')}}'
  icon: mdi:thermometer
  entity: climate.woonkamer
  tap_action:
    action: call-service
    service: script.turn_on
    data:
      variables:
        sensor: "{% ((( states('sensor.woonkmr_set_point') | round(2)  ) + ( 0.2 | float ))| round(1)) %}"
        entity_id: "climate.woonkamer"
    target:
      entity_id: script.stel_temperatuur_in
  double_tap_action:
    action: call-service
    service: script.turn_on
    data:
      variables:
        sensor: "{% ((( states('sensor.woonkmr_set_point') | round(2)  ) - ( 0.2 | float ))| round(1)) %}"
        entity_id: "climate.woonkamer"
    target:
      entity_id: script.stel_temperatuur_in

If I call a service script without passing variables, it triggers, this just does nothing.

You are using {% %} instead of {{ }}. That effectively returns a null value for the temperature instead of a numeric value.

Thanks…

Changed the {% to {{ but stil no joy.

Am getting an log entry now, so …progress

Logger: homeassistant.components.script.stel_temperatuur_in
Source: helpers/script.py:410
Integration: Script (documentation, issues)
First occurred: 21:46:55 (45 occurrences)
Last logged: 22:44:40

Stel Temperatuur In: Error executing script. Error for call_service at pos 1: Template rendered invalid entity IDs:
Stel Temperatuur In: Error executing script. Invalid data for call_service at pos 1: expected float for dictionary value @ data['temperature']

Also tried switching the ’ and " around as that will sometimes help.

                tap_action:
                  action: call-service
                  service: script.turn_on
                  data:
                    variables:
                      sensor: '{{ ((( states("sensor.woonkmr_set_point") | round(2)  ) + ( 0.2 | float ))| round(1)) }}'
                      entity_id: climate.woonkamer
                  target:
                    entity_id: script.stel_temperatuur_in
                double_tap_action:
                  action: call-service
                  service: script.turn_on
                  data:
                    variables:
                      sensor: "{{ ((( states('sensor.woonkmr_set_point') | round(2)  ) - ( 0.2 | float ))| round(1)) }}"
                      entity_id: climate.woonkamer
                  target:
                    entity_id: script.stel_temperatuur_in

Ok, strange, was working in raw, but closed the screen and went back in and found this.

 data:
                    variables:
                      sensor: >-
                        {{ ((( states("sensor.woonkmr_set_point") | round(2)  )
                        + ( 0.2 | float ))| round(1)) }}
                      entity_id: climate.woonkamer

should that happen?

Sorry, I missed that you didn’t have a float filter after the states(). The states of entities are always strings, so you need to convert them before performing math operations with them.

...
                tap_action:
                  action: call-service
                  service: script.turn_on
                  data:
                    variables:
                      sensor: '{{ ( states("sensor.woonkmr_set_point") | float(0) | round(2) + 0.2) | round(1)  }}'
                      entity_id: climate.woonkamer
                  target:
                    entity_id: script.stel_temperatuur_in
                double_tap_action:
                  action: call-service
                  service: script.turn_on
                  data:
                    variables:
                      sensor:  '{{ ( states("sensor.woonkmr_set_point") | float(0) | round(2) - 0.2) | round(1)  }}'
                      entity_id: climate.woonkamer
                  target:
                    entity_id: script.stel_temperatuur_in
....

Thanks fo helping man! Appreciated.
However…still nothing but the same error…

You can’t template in the frontend. Make a plus/minus script

alias: Verhoog Temperature Increment
variables:
  value: "{{ states(sensor) | float + increment }}"
sequence:
-  service: script.verhoog_temperatuur
   data:
     entity_id: "{{ climate }}"
     sensor: "{{ value | round(1) }}"

then in the frontend

                tap_action:
                  action: call-service
                  service: script.verhoog_temperature_increment
                  data:
                    sensor: sensor.woonkmr_set_point
                    climate: climate.woonkamer
                    increment: 0.2
                double_tap_action:
                  action: call-service
                  service: script.verhoog_temperature_increment
                  data:
                    sensor: sensor.woonkmr_set_point
                    climate: climate.woonkamer
                    increment: -0.2

Who knew?!
Didn’t realise you can’t template in the frontend…I’m guessing that pertains to the “tap_action” parts? (As I am using a mushroom template…which should be…no?)

Thanx!