#Change blueprint based on whether inputs are blank or not

1 messages · Page 1 of 1 (latest)

burnt pawn
#

I have optional inputs in my blueprint. I am making a motion + occupancy + light level activated light.

I have the following (relevant) inputs:

  • Illuminance sensor - used to control if the light should turn on upon motion
    • Entity-provided threshold - for dynamic light thresholds, an entity can be used to provide the maximum brightness of the illuminance sensor
    • Fixed-number threshold - for fixed light thresholds, a number input that does not change
      The illuminance checks should be completely optional, I want to skip parts of logic completely if these fields are not filled out.
  • Occupancy sensor - used to keep the light turned on, even if there is no motion
    This should be optional too, if not, these checks shouldn't exist.

I want something like:

input:
  occupancy:
  illuminance:
  threshold_entity:
  threshold_fixed:

trigger:
  {% if is_defined(!input 'occupancy') %}
  - type: state
    entity_id: !input occupancy
    from: "on"
    to: "off
  {% endif %}

action:
  - if: 
      condition:
        {% if is_defined(!input 'illuminance') %}
        ...
        {% endif %}
      then: ...
lime pasture
#

I don't think you can write code like you're proposing, but you can maybe make a template trigger instead.
Like if occupancy is not defined it is false, otherwise it is true when occupancy sensor is on

#

similarly a template condition

tight dagger
#

I would suggest something different.

burnt pawn
#

i'm listening!

tight dagger
#

Have your inputs, but set a default to something that is other that you know what it is

#

Then in your code check if it's the default, if it is consider it not usable, and code to go that way.

burnt pawn
#

checking if its default still involves templating though, so surely it's easier to just use karwosts' method?

#

and how do I check if an input is defined

tight dagger
#

There are lots of ways. Generally in a blueprint I try to cover everything with a default and also trigger kind of general, then put the templates , conditions, etc in the conditions or choose statements. Makes in much more tobust.

tight dagger
#

It tries to make it into something or errors if you call for an entity and don't give it one.

#

BC of limited templates, template triggers are tricky and if you can avoid them, I would. It is a template, but you have to be careful what you put there so it will render and all your jinjas are not available.

split jewel
#

@burnt pawn use this:

input:
  occupancy:
  illuminance:
  threshold_entity:
  threshold_fixed:
trigger_variables:
  occupancy_var: !input occupancy
trigger:
  - type: state
    entity_id: !input occupancy
    enabled: "{{ occupancy_var is not none }}"
    from: "on"
    to: "off
#

you might need to alter the template in enabled

#

FYI @tight dagger @lime pasture

lime pasture
#

is that a recent change?

split jewel
#

Pretty sure G added this

#

it's recent in the past 6 months

lime pasture
#

I thought it would carp on validation

split jewel
#

@outer temple didn't you add this?

lime pasture
#

probably did. I think I remember discussion about it, neat if it got merged

split jewel
#

I think there was a "don't validate if disabled" pr

#

going off memory here, which ... you know 😉

outer temple
split jewel
#

For some reason, I thought you added limited_templates to the enabled field on all triggers, as well as some other PR's related to it

#

Sorry for bothering you, if you didn't

outer temple
#

Wasn’t me. But I added availability to some other integrations so maybe there is the mixup

split jewel
#

Hmm, ok

#

ah farmio

tight dagger
#

Nice trick. I might pull this into a cookbook entry, mostly so I can find it myself later...

split jewel
#

it's covered in the documentation pretty well

tight dagger
#

I'll point there.

tight dagger
split jewel
#

LGTM