Node-red feedback from action call

I want to create more “inteligent” way of renewing ssl certificate than

  1. run addon restart letsencrypt
  2. folowed by homeassistant restart.
  3. hope for the best.

Moust of the things i figured out already but i have one key thing missing. When you restart letsencrypt it output some informations like this for example:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

Certificate not yet due for renewal


Certificate not yet due for renewal; no action taken.


My question is this. How can i catch that output in node-red. i tried to put in “output properties” “msg.log = results” but my msg.log comse moustly empty or with basic info about execution like date etc.

So i ask someone smarter than me for any help / clue.

For those who want to know why i need this. I want to create automation in nodered like this.

-----repeat everyday ------

  1. i want to check expiry date of certificate.
  2. if date is bigger than 20 days from now do nothing
  3. if date is between 20-10 days try to restart letsencrypt
    a) if success (based on logs letsencrypt provide)
    - restart homeasistant
    - read new ssl expiry date and confirm that is >20 days. if not report error
    b) if error (based on letsencrypt logs) wait for next execution window (1day for me )
  4. if date is <10 days (we know there is a problem becouse we have 10 retries failed already) start reporting error in ssl certificate renewal + add in message information from letsencrypt logs. (for me it is sms on my phone)

Running any Action using the WebSocket node in Node-RED just passes this Action to Home Assistant to run, so you get the same result as if you run the Action using Developer Tools > Actions; which is always a good place to start checking Actions.

All Actions now return a ‘result’, but most Actions have nothing to return. The ‘get_forecasts’ and ‘get_statistics’ actions certainly return something, so we can expect to see a ‘return’. Asking HA to restart an add-on is not likely to return anything of value. HA just restarts the add-on - assumes it works - nothing to see. So I don’t think that you will never see anything back as the ‘return’ for this action.

Most programs are set up to be run, in Linux, using a command line prompt, with the standard input being the keyboard, and the standard output being the screen or terminal. There is also a ‘standard error’ where error messages go. When things are run as HA add-ons, they end up inside a docker container, and the ‘standard output’ and ‘standard error’ have to go someplace else, since there is no CLI. Inside HA all standard out now goes to journald, which is a central log file.

So, whilst you can see the add-on starting and issuing messages, and can probably see them inside the ‘log file’, actually getting at them is much more of a challenge.

If the information you want is just part of the stdout stream, then you will have to either extract the add-on related logs, or actually use the HA CLI to restart the add-on and capture the stdout as it happens.

It is possible to add SSH access to Home Assistant, either via the main Terminal & SSH add-on, or the Advanced SSH & Web Terminal. I can use either to access HA and the provided ‘ha’ CLI program, and thereby run the command ha addon <slug> restart, which does the same as the action and generates all the stdout stream as it happens.

There are SSH nodes for Node-RED, but I have had little success in setting anything up so as to be able to run the ha CLI commands over SSH from Node-RED, let alone retrieve the stdout stream as a return. Someone else may know how to do this - it would be interesting to be able, for example, restart Node-RED using Node-RED and to catch and analyse the stdout stream for error messages etc. And before anyone points out, yes if you restart Node-RED from Node-RED, then Node-RED as an add-on is not running so you can’t use it. You could, however, run this from a separate instance of Node-RED…

I suspect that the simple answer to all of this is to just do as the letsencrypt add-on suggests; run an HA automation daily to restart the add-on.