Trigger node compare boolean value

Hey guys, I’m having some issues with the constraints of a trigger node. I have an automation in HA that when my phone starts charging at night (tracked via life360) I turn off a bunch of lights in my house. I’ve been messing with the trigger node in NR as I’m trying to switch things over. For the life of me I can’t figure out how to compare a true/false in the constraints. It always makes it a string, so it’s “true” instead of true. The attribute of battery_charging is a boolean. This causes the comparator to fail every time. Any idea on how to make the comparatorvaluetype a boolean?

constraint: object

id: "4cjwzx8wpaa"

targetType: "this_entity"

targetValue: ""

propertyType: "property"

propertyValue: "new_state.attributes.battery_charging"

comparatorType: "is"

comparatorValueDatatype: "str"

comparatorValue: "true"

constraintTarget: object

actualValue: false

comparatorResult: false

check if it’s equal to the string true…

{{ json_value['comparatorValue'] == 'true' }}

assuming you are using templates/jinja and that you are pulling it from a json object.

If you are pulling it from a sensor or something else:

{{ x.x.attributes.comparatorValue == 'true' }}

Thanks for the help. I’m using the trigger node and the constraints that are in there. I tried to put in some jinja stuff but couldn’t get it to work either. Here is what I have.

[{"id":"93469bc4.121608","type":"trigger-state","z":"959b8126.8ec13","name":"","server":"d8c78a5.039f578","entityid":"device_tracker.life360_david","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"7rkaad2vlil","targetType":"entity_id","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"home"},{"id":"4cjwzx8wpaa","targetType":"this_entity","targetValue":"","propertyType":"property","propertyValue":"new_state.attributes.battery_charging","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"true"},{"id":"j2gef6xjqa","targetType":"this_entity","targetValue":"","propertyType":"property","propertyValue":"old_state.attributes.battery_charging","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"false"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":320,"y":340,"wires":[["bd63ee62.6211d"],["2b0276.a0b3ad8a"]]},{"id":"bd63ee62.6211d","type":"debug","z":"959b8126.8ec13","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":300,"wires":[]},{"id":"2b0276.a0b3ad8a","type":"debug","z":"959b8126.8ec13","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":620,"y":380,"wires":[]},{"id":"d8c78a5.039f578","type":"server","z":"","name":"Home Assistant"}]

The constraints are if I’m home, my old_state is false (not charging) and my new_state is true (charging). The constraint is forcing the true to be a string, so I end up comparing a string to a boolean.

So what component are you pulling this from? Just life360?

Yep. I think it’ll probably be better to just use the trigger node to trigger the change, and then some other nodes to do my verification.

2 Likes

@Kermit thank you so much!!! On mine, it didn’t look like there was a dropdown to select boolean (see below). However once I click on the small sliver it’s there.

Before clicking on the “sliver”:
image

image

If you don’t mind me asking what browser and OS are you using?

I’m using Chrome browser on Windows 10 to access it. My home assistant is running on a Raspberry Pi 3 B+, and was accessed through my duckdns if that makes a difference. Node-Red v3.1.2, HA v0.93.2