Debug Mode for Home Battery Control in Home Assistant Not Reliably Reflected in Node-RED
Describe the bug
When enabling debug mode for Home Battery Control (input_boolean.house_battery_control_is_debug_mode) in Home Assistant, some users observe that nothing appears to happen within Home Assistant itself. This issue does not affect all users, but has been reported by multiple individuals.
Analysis
The issue appears to stem from the way the debug mode current state node in Node-RED handles the input_boolean.house_battery_control_is_debug_mode entity. Specifically, the global variable global.debug_mode is not reliably set to true when the entity is read via the current state node and its output is directly assigned to the global variable.
Proposed workaround
If the output property for the global variable debug_mode is removed from the debug mode current state node, and instead a switch node is placed after it to evaluate the payload (on/off), followed by a change node that explicitly sets global.debug_mode to true or false, the expected behavior is restored.
Steps to reproduce
- Click the debug button in the Home Battery Control debug tab, so that the
input_boolean.house_battery_control_is_debug_modeentity in Home Assistant is enabled. - Check the value of the global variable
global.debug_modein Node-RED. In some cases, it will remainfalse.
Expected behavior
Activating the input_boolean.house_battery_control_is_debug_mode entity in Home Assistant should result in global.debug_mode being set to true in Node-RED, triggering any associated debug behavior.
Additional context
This issue may be related to how the current state node handles output properties when writing to global variables. The workaround suggests that explicitly routing the payload through a switch and change node improves reliability.
The following screenshots illustrate the problem:
- In Home Assistant, the debug icon for
input_boolean.house_battery_control_is_debug_modeis clearly yellow, indicating that debug mode is enabled. - However, in Node-RED, the global variable
global.debug_moderemains false, even after debug mode is activated.
This confirms that the expected synchronization between the Home Assistant input_boolean and the Node-RED global variable does not occur reliably in some setups.
After applying the proposed workaround, removing the global variable assignment from the current state node and instead routing the payload through a switch and change node, the global variable global.debug_mode is now correctly set to true when debug mode is enabled in Home Assistant.
This confirms that the issue lies in how the current state node handles direct global assignments in some setups.
@codebob Would you like me to create a PR with this adjustment so you can test it directly?
Ah great find Mike. Could you confirm this flow has the same result for you? Start-flow-with-fix.json
No, unfortunately it doesn’t work. Even though the ‘On debug’ event is triggered, the ‘debug node?’ switch does nothing because global.debug_mode is still set to false.
Could you post your flow here @MikedaSpike
I am breaking my head what in node-REDs name could cause the difference.
I'm not trusting the "Home Assistant boolean" either, in the current state node.
I did not expect setting the global variable in a change node or via a function nodes could create a difference
Sure @gitcodebob here it is :
I am breaking my head what in node-REDs name could cause the difference.
I'm not trusting the "Home Assistant boolean" either, in the current state node.
I did not expect setting the global variable in a change node or via a function nodes could create a difference
I don't understand either. But honestly, two months ago I had no idea what Node-RED was, so I've made a lot of progress in that time 😄
@MikedaSpike you are on to something. I've created a "function node" which should replicate your approach:
Mikes-solution-as-a-function.json Does this work for you as well?
sorry, didn't had time to test yesterday, but 4.4.0 (https://github.com/gitcodebob/marstek-venus-rs485-node-red/commit/f31ea5b8fe7e5dc2bbece89dc3d4edfa9c965ea8) fixed it ! Nice job !