Referencing an Entity in the Node-Red function

I have a function called calendar.important_dates.

In the developer tools, it has the following details:

message: 'Birthday: Joe Smith'
all_day: true
start_time: '2021-10-05 00:00:00'
end_time: '2021-10-06 00:00:00'
location: ''
description: ''
offset_reached: false
friendly_name: Important Dates

I have the following set up in Node-Red

What I am trying to work out is how do I reference the entity in the function?

I have tried
msg=calendar.important_dates.message
but get told that “ReferenceError: calendar is not defined”

var states = global.get('homeassistant.homeAssistant.states');
var calendar = states["calendar.important_dates"];
1 Like

Thanks for that, just one more question.

My function is now

var states = global.get('homeassistant.homeAssistant.states');
var calendar = states["calendar.important_dates"];
return calendar;

When the debug mode is set to output the complete object I see the data that I am looking for.

I then try something like output msg.calendar.message but get told “msg.calendar.message : undefined”

What do I put into the output to show just a particular part of the object.

Worked it out using http://stevesnoderedguide.com/node-red-message-object.

In this case, output is msg.attributes.message

Why not just use the current state node if you’re not going to use the values in the function node anyway?

var states = global.get('homeassistant.homeAssistant.states');
var calendar = states["calendar.important_dates"];
msg.calendar = calendar;
return msg;

Is what you typically use in a function node, but for this use case I would use current state node.

Thanks, the current state node does make more sense.

But it appears that there is still something that I don’t understand. I have two full days entries in my calendar for today but only one appears in the current state. Should they not both appear in some sort of list?

Both entries appear in the Dashboard, Calendar Card Configuration, card.

It’s impossible to answer when I can’t see any of it.

The lovelace dashboard shows

The Devloper tools

And the debug output

With debug output being: msg.data

10/2/2021, 10:32:59 PMnode: 99dcf9eb253385ee
Topic : msg.data : Object
object
entity_id: "calendar.important_dates"
state: "on"
attributes: object
message: "Birthday: Paul xxxxx"
all_day: true
start_time: "2021-10-02 00:00:00"
end_time: "2021-10-03 00:00:00"
location: ""
description: ""
offset_reached: false
friendly_name: "Important Dates"
last_changed: "2021-10-02T04:15:09.010611+00:00"
last_updated: "2021-10-02T04:15:09.010611+00:00"
context: object
id: "e6ddf9caf8206b4920abd4dd62edf84a"
parent_id: null
user_id: null
timeSinceChangedMs: 19070907
original_state: "on"

i.e. only the one entry is there in the Node-Red flow. The 2nd Test entry does not show other than on the dashboard.

But the second is not visible in the entity either.
I have no clue where that comes from if it’s not in the entity

Yeah, it’s got me confused. But thanks for taking a look :slight_smile:

What is the state of the sensor in nodered global context?

So the current calendar is

And the entity state still only shows the first entry for the day: