Email notification including sensor values - is it possible using node.send

Hi,

I’d like to set up node red to deliver emails to send out when a pump is being triggered, however I’d like sensor values to be present, and thought something like this may do it (function node):

{
  node.send({
    topic: "Subject: Front Pump Active...",
    payload: "Rain fall today: " + sensor.netatmo_thermostat_indoor_rain_rain + " Water Level: " + sensor.water_tank_level,
  });
}
    return;

if anyone can help with the above, that would be amazing,

Thanks
Tony

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/config-server.html#context-example

You can’t just use sensor.something in NodeRed. It is a HA notation style.
In NodeRed normally have to request sensor states by using Current State nodes and then send that along with the messages in the flow.
However there is a trick, since all states in HA is stored in global variable too.
You can can view the global variable by opening the Context Data (stacked discs) sidebar from the upper right menu and then click the refresh icon to the right of the Global headline.
The values in there can be retrieved with the global.get command.

{
  node.send({
    topic: "Subject: Front Pump Active...",
    payload: "Rain fall today: " + global.get('homeassistant').homeAssistant.states["sensor.netatmo_thermostat_indoor_rain_rain"] + " Water Level: " + global.get('homeassistant').homeAssistant.states["sensor.water_tank_level"],
  });
}
    return;

Hi Wally,

thanks for your help, wonder if you can advise further…

I’ve got the code as you provided, however when the email notification comes through, i get:

Rain fall today: [object Object] Water Level: [object Object]

Could this be due to changing the name away from homeassistant? If so, where is this set? AFAIK, I’ve not changed the name, but wouldn’t swear to it!

Thanks
Tony

The object word just means you have not extracted a single value, but rather a bunch of values and it have no way of showing that, so you need to correct you path.
Open the Context Data and update the global section as describe earlier.
Now you should see the data and you can follow the path in the global.get command down the hierarchy to the data you want. You might have to put more .something or [x] behind the command to reach the value you want.
If it goes wrong then post a picture of the sensor in the Context Data here and we can help to adjust the line.

Thanks Wally, seems the following is working:

payload: "Rain fall today: " + global.get('homeassistant').homeAssistant.states["sensor.netatmo_thermostat_indoor_rain_rain"].state + " Water Level: " + global.get('homeassistant').homeAssistant.states["sensor.water_tank_level"].state,

resulting in:

Rain fall today: 0 Water Level: 10

Thanks for your help
Tony