Converting a value template trigger to node red

Hi

As part of a learning experience I am trying to rewrite the following automation into node-red. I am stuck right off the bat in trying to build the trigger which fires if an mqtt topic != an entity state. Can anyone point me in the right direction please?

- id: kitchen_state
  trigger:
    platform: template
    value_template: >
      {{ states("binary_sensor.kitchen_mqtt") != states("light.kitchen_group") }} 
  condition:
    condition: state
    entity_id: input_boolean.disco_override
    state: 'off'
  action:
    - delay: '00:00:02'
    - service: script.light_toggle
      data:
        entity_name: "light.kitchen_group"
        off_command: "Light7"
        on_command: "Light10"    

You can use a trigger node for that. Simply add your entities like that:

It will only allow once the two states are different from each other.
How it works: ligh.flur_1 is the trigger. The node then compares the first constraint: light.bedroom_dresser != state of the trigger. If true, its allow, otherwise block.

Thanks @AlmostSerious, that’s really helpful.

One challenge I am having is that the trigger node appears to be triggering a random number of times for a single trigger event (most often twice). This example the trigger entity switched to become different from the constraint entity:

image

So the message payload “on” gets sent twice.

The second the trigger entity switched to become the same as the constraint entity:

image

Here the message payload first sends “on” and then “off” the end state.

Any thoughts?

Ta
S

Can you export and share your flow please?

Here it is, but at this stage it is just the trigger node and a debug node. I have seen similar behaviour, i.e. multiple outputs from a single event, on the poll state node too so I have a suspicion this might be a HA / Node Red issue

[{"id":"7becea40.e4f164","type":"tab","label":"Bench","disabled":false,"info":""},{"id":"a5e5ae4.97b8e5","type":"trigger-state","z":"7becea40.e4f164","name":"Study state","server":"7b019ae4.9d4824","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"light.study_group","entityidfiltertype":"exact","debugenabled":true,"constraints":[{"id":"77p9ayqkoyn","targetType":"entity_id","targetValue":"binary_sensor.office_mqtt","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"entity","comparatorValue":""}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":130,"y":100,"wires":[["a72c39ad.963768"],[]]},{"id":"a72c39ad.963768","type":"debug","z":"7becea40.e4f164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":350,"y":100,"wires":[]},{"id":"7b019ae4.9d4824","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

as expected, you are not actually comparing against the triggering state. Make sure to put entitiy.state image

Good spot, thanks, however having corrected it the flow still fires multiple times. Here is the output when the trigger entity is switched to match the tested entity (and so the “is not” condition is failed):

So the trigger fires both to the allowed (incorrectly) and then the blocked port (correctly).

I think I have resolved it, the light.study_group comprises 4 bulbs controlled via deconz. I suspect the bulbs are being turned on and off at fractionally different times resulting in the state of light.study_group changing a few times per trigger. I suspect I will either need to trigger it off the state of a single bulb or put something else in between which can only be off if everything is off or on if anything is on.

However that does not solve the mystery as to why Poll State fires multiple times, which is still the case when looking at a single bulb (it even seems to manage to fire the same output through an RBE node). That can be a problem for another day!

EDIT: Just updated node red to v.6.3.0 and Poll State now seems to behave as expected.