Having problems with incredibly basic node setup

I have tried making a lot of permutations on a very simple setup. I plug in my phone and a counter on HA increments. I have tried this many different ways and none of them work. Sometimes, the sensor on Node Red has a message that informs the user it is doing its job properly (showing like “detected” or not).

However, I cannot get the stupid counter to increment.

  1. It has been deployed.
  2. The addon has been reinstalled.
  3. Various different sensor entities all have the same problem - none of them cause the counter to increment. They do display they are working as I intend them to. A sample of a node is shown below - this node is me trying to test something that’s basically always true.
  4. I don’t see a way to test the counter node directly. I right click and try “activate node” but nothing happens. The counter settings are shown below.
  5. The “show notification” has never showed me a notification.


image

There are 2 errors in the logs. An encrypted secrets error, and a one about projects. The encrypted secrets error I cannot figure out for the life of me. I have typed in a decent password into the config and tested it on that Pwn site - it’s a safe password. The addon config doesn’t give me any instructions beyond just entering a password to the config tab.

Welcome to Node-RED
===================
16 Aug 17:04:05 - [info] Node-RED version: v3.0.2
16 Aug 17:04:05 - [info] Node.js  version: v18.17.0
16 Aug 17:04:05 - [info] Linux 6.1.39 x64 LE
16 Aug 17:04:06 - [info] Loading palette nodes
16 Aug 17:04:07 - [info] Dashboard version 3.5.0 started at /endpoint/ui
16 Aug 17:04:08 - [info] Settings file  : /etc/node-red/config.js
16 Aug 17:04:08 - [info] Context store  : 'default' [module=memory]
16 Aug 17:04:08 - [info] User directory : /config/node-red/
16 Aug 17:04:08 - [info] Projects directory: /config/node-red/projects
16 Aug 17:04:08 - [warn] No active project : using default flows file
16 Aug 17:04:08 - [info] Flows file     : /config/node-red/flows.json
16 Aug 17:04:08 - [warn] Encrypted credentials not found
16 Aug 17:04:08 - [info] Server now running at http://127.0.0.1:46836/
16 Aug 17:04:08 - [info] Starting flows
16 Aug 17:04:08 - [info] Started flows
16 Aug 17:04:08 - [info] [server:Home Assistant] Connecting to http://supervisor/core
16 Aug 17:04:08 - [info] [server:Home Assistant] Connected to http://supervisor/core
[17:04:08] INFO: Starting NGinx...
16 Aug 17:05:42 - [info] Stopping flows
16 Aug 17:05:42 - [info] [server:Home Assistant] Closing connection to http://supervisor/core
16 Aug 17:05:42 - [info] Stopped flows
16 Aug 17:05:42 - [info] Updated flows
16 Aug 17:05:42 - [info] Starting flows
16 Aug 17:05:42 - [info] Started flows
16 Aug 17:05:42 - [info] [server:Home Assistant] Connecting to http://supervisor/core
16 Aug 17:05:42 - [info] [server:Home Assistant] Connected to http://supervisor/core

Your first node is a “current state” node and there’s nothing connected to the left of it. This node fetches the current state, but does not start a flow based on a change of state. You need to use an “events: state” or “trigger:state” node to initiate a flow from a state change.

Errors in the logs:
These are warnings only. The projects warning is because you don’t have projects enabled (which is the default, and I don’t have projects enabled either - it is an ‘extra’ feature).
The encrypted credentials warning is more serious, suggesting that Node-RED can’t find your flow credentials file. Not an issue I have had, but I note that the credentials secret password is controlled by the HA addon configuration (not the Node-RED settings file) and this should generate a flows_cred.json file in the config/node-red folder. I believe that the password must be set when the addon is first created, and cannot be changed thereafter. My guess is that, to fix this, you would need to uninstall the NR addon, check the node-red folder has gone (I don’t think it is removed automatically, hence the old files remain) and re-install from scratch, setting the password first. TAKE A BACKUP OF ALL FLOWS FIRST.

The flow:
As @michaelblight says, the flow has nothing to set it running (trigger) and hence it will never do anything. An ‘events: state’ node is indeed probably the best option. This node continually listens to event change messages in HA. If set to the correct entity, it will respond and trigger an output (to start the flow) whenever the state of the given entity changes.
This node can be configured to just listen to one entity, and to ignore any states that are undefined or where the change is equal to the previous value, and will thus only trigger then the state goes from a given known value to another given known value.
Also, you can set the ‘if state’ - is - value, and this will provide two outputs, one for state=value is true, the other for false.

If we ensure that the given test value is the correct one, then the node will fire, on the top output, when the state changes to the given value. My entities have a state value of ‘on’ and ‘off’, so I am testing for ‘on’.

Service call:
Yes, computers are stupid, so you have to tell HA exactly what to do, otherwise it won’t work.

Services are execution calls that HA provides so as to be able to do things to entities and HA itself . There are a lot of them, and they can be tested using the developer tools>services sandbox. If you type in ‘counter’ in the service box you will see all the services than work with ‘counter’ entities. Selecting the counter:increment will allow you to select the entity - and HA will only show those entities that are ‘counters’. The ‘action’ button will run the service, so you can test the service call works.

All counters are setup with an incremental step. Calling the ‘increment’ (or decrement) service call just adds or subtracts this step value from the count, so it is worth checking that this step value is set to ‘1’.

Note that every service is different, and many require additional data. The counter:increment is almost unique in that no additional data is required. The counter:set call is used to change a counter state value, and this requires the ‘set-to’ value. The developer tools / services is a good way to check out what services are available, which entities can work with the service, and what additional data is required. Additional data has to go in the ‘data’ field, and the Node-RED service node has a great option to load example data (but not in this case as no data is required).

Testing:
I have knocked up a flow that monitors the ‘charging’ sensor on my phone (uses the HA app) to update a counter (created using HA helper). This works.
I have added debug nodes, and an inject node. This allows me to check what is going on as output from the flow, and also to trigger the ‘counter:increment’ node directly.

It is indeed all a bit baffling at the beginning. I hope this helps you to get it working.