Set variable in local automation remotely

I am trying to make a dosing system. Open a valve until a defined volume is in a container.
Automation can do it if it is the same volume every time, but I want to be able to change the volume.
As I see it I need a variable in my automation that I can modify from the outside.
Is there a way to do this? Ideally a way that I can use to send the setpoint from Nodered.

Thanks
Preben

Probably setting up a template number would do it I’d have thought.

Sounds promising, but this doesnt work:

number:
  - platform: template
    name: "TargetWeight"
    id: targetweight
    optimistic: true
    min_value: 0.0
    max_value: 100.0
    step: 0.1

sensor:
  - platform: hx711
    name: "HX711 Value"
    on_value_range:
      - above: targetweight
        then:
          - switch.turn_off: waterrelay
      - below: targetweight
        then:
          - switch.turn_on: waterrelay

If i replace targetweight with a number, it works.
I cant figure out what the correct syntax is.

I think those above and below values aren’t “templatable” so you can’t use a variable.

What I usually do in this situation is create a template binary sensor called “is_above_weight_target”. The example is pretty close to what you want to do.

Then I put those switch actions you have there under on_press and on _release.

You’ll need to add an id to your sensor then the compare should be close to below. You might not need the second .state.

(id(hx711_value).state > id(targetweightstate).state)

Tried making the binary sensor:

binary_sensor:
  - platform: template
    name: "Mashtun Full"
    id: "mashtunfull"
  lambda: |-
    if (id(hx711_value).state > id(targetweight).state) {
      return true;
    } else {
      return false;
    }

But I get a syntax error regarding the - in front of platform. I pretty much copypasted everyting, reread the instructions, but I still cant figure out what im doing wrong.

Your lambda block needs to be bumped in two spaces to start… Same level as id. Indentation is critical with yaml.

Ahh this is a home brew project… Nice.

IT WORKS!!!

binary_sensor:

  - platform: template

    name: "Mashtun Full"

    id: "mashtunfull"

    lambda: |-

      if ((id(hx711_value).state < id(targetweight).state)) {

      // Level reached.

      return true;

      } else {

      // Mashtun not full.

      return false;

      }

    on_press:

      then:

        - switch.turn_on: waterrelay

    on_release:

      then:

        - switch.turn_off: waterrelay

Even though I only understand half of what i’m doing :wink:
Feeling great while standing on the shoulders of giants.

Thank you for your help

1 Like