I have just come across a weird issue with using template binary sensors.
I have input_boolean.test and created a binary sensor off of the input boolean. In lovelace, when I turn the boolean off, the sensor says off, when I turn the boolean on, the sensor says on. However, when I go to use it in an automation, the binary sensor is reversed???
You’re referencing itself in the template. This means its pulling the state from the state machine, which is the previous state for your sensor. Change your icon template to use the input_boolean.
I have noticed that if you use call state node too soon after a state change then it will get the previous state.
I have, with a crude setup, concluded that it’s more than 200 ms and less than 500 ms needed to get a correct value.
I just stopped at 500 because it doesn’t really matter.