I have a requirement to send a particular string based on some other states.
I have a mode that can be 1 or 0, and a value ie 23. So the string will be 123 or 023 depending on the states. The value here 23, is going to be an adjustable number in HA, this is already in place.
How can I determine this string and then use it as a variable in an mqtt payload?
I currently have some automations that trigger scripts based on the the states that would ultimately select the mode, so I imagine it would make most sense that in those scripts a variable will be updated, and then call a thirds script to send the mqtt message?
So would it make sense that I create a helper string, and from either of the two scripts (that would be triggered when the mode needs to be turned on or off), update the string with the appropriate 1 or 0 + the value.
I may be answering my own question but Ive literally just got the first automation and scripts set up and working. Thanks
when trv boost on is triggered the mode will need to be “1” and when boost off is triggered is needs to be “0”. The value will be from the helper which selects a value with no decimal places but the resulting output needs to be a string for the mqtt message.
For future reference, the tilde operator performs concatenation. The plus operator also performs concatenation but only if the values are strings. If the values are numbers then the plus operator will (obviously) perform an arithmetic addition.