28 likes
·
8.3K reads
2 comments
Great article! Last week I discovered two (advanced?) things that you might be interested in: getting flow variables in subflows and the status message
Getting a flow variable from a subflow
The sun position dictates a flow variable in my lights automations. It sets a brightness modifier so I'm not blinded at night. This is how I format the JSONata for the light.turn_on
service call:
{
"transition": 2,
"brightness_pct": ( 0.01 * $flowContext('$parent.sun_brightness_modifier') ) * $env('BRIGHTNESS_BASE')
}
Mind the $flowContext('$parent.variable_name')
syntax: with $parent you get access to the subflows parent variables.
Outputting a node status for a subflow:
The status
node lets you update the message that's underneith the subflow node. Now, my formatting is not very pretty but the information is very useful!
The JSONata for the message formatting:
{
"fill": "green",
"shape": "dot",
"text": $join(['On:', $env('ENTITY_ID'), "at:", $now()], ' ')
}
I have one problem I can't figure out and thought I'd make a comment since others may have the same issue.
This example sets the message text in the subflow node when it is called (message and title). I want to pass in the message text to the node and not have the message text hard coded in that node.
I want the text of my message sent to the subflow node as msg.payload. However, this web pages' example requires the message to come through as a string, not an object. I can't figure out how to reference or convert the message text from msg.payload into a string in the subflow node, or even in the subflow itself in the mobile notify node.