Doing math with Input variables and sensor States

Abridged version of my code:

blueprint:
  name: magic with input
  description: magic with input
  domain: automation
  input:
    mod_value:
      name:  Mod Value
      description: This modifies another value
      default: 0
      selector:
        number:
          min: -100
          max: 100
[.....]
action:
  - variables:
      command: "{{ trigger.to_state.state }}"
  - choose:
      - conditions: "{{ command == 'on' }}"
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: '{{ states("sensor.global_brightness") | float }}' **<-- I want top add/substract the !input mod_value**

so as the code shows I have a modification value and this value I want to substract/add to the brightness_pct value the catch this value is read from a sensor that stores my global brightness value?

Usually, if I would be to do math with it, I could do it like this : '{{ states("sensor.global_brightness") | float * 100}}' to multiply what ever the sensor returns by 100 but I don’t know how to do the same thing with my input value

thx for the help :slight_smile:

I don’t use blueprints but I assume the variable you create acts as any other variable so this should work:

brightness_pct: '{{ states("sensor.global_brightness") | float + mod_value }}'

Convert the !input to a variable. This is done in nearly all blueprints somewhere, look in the exchange for an example. It’s the most common action when using blueprints, as variables can be used in templates but !inputs cannot.

I prefer to have you go look at others code rather that write something for you because you are certain to learn something else along the way, if nothing else, learn where to find answers.

2 Likes