Multiple conditions on variables

Hello,
I’m trying to setup an AND condition based on variables values without success so far.

- id: d1b2862b-fbfe-408c-ad59-3a5d7c528ecd!
  alias: Store DZ light slider value
  variables:
    indexes:
      388: input_number.idx388
      377: input_number.idx377
      387: input_number.idx387
      44: input_number.idx44
      389: input_number.idx389
      256: input_number.idx256
    entity: '{{ indexes.get(trigger.topic.split(''/'') | last | int(0), ''unknown'')
      }}'
  trigger:
    platform: mqtt
    topic: domoticz/out/#
  condition: '{{ trigger.payload_json.nvalue !=0 }}'
  action:
    service: input_number.set_value
    target:
      entity_id: '{{ entity }}'
    data:
      value: '{{ trigger.payload_json.svalue1 }}'

The above code works but I need to add a second condition.
I tried many flavors like:

condition: '{{ trigger.payload_json.nvalue !=0 }} and {{ entity != "unknown" }}'

or

  condition: and
  conditions:
    - condition: '{{ trigger.payload_json.nvalue !=0 }}'
    - condition: '{{ entity != "unknown" }}'

What is the proper way of doing it?
Thank you

This should be:

condition: '{{ trigger.payload_json.nvalue | int(<choose a default value>) !=0 and entity != "unknown" }}'

Either option should work though. Does the second one not work? Any errors? Are you sure that the entity variable has the expected value?

As of matter of fact I just found the solution.

  condition: '{{ trigger.payload_json.nvalue !=0  and  entity != "unknown" }}'

Thank you for your help

1 Like