Node-Red Triggers

So been racking my brain for a good day now and searching various ways to do something and have drawn a blank.

So from time to time there is a message delivered from a 3rd party (an example follows)

next_joined_event_start: "2024-02-29T20:00:00+00:00"
next_joined_event_end: "2024-02-29T21:00:00+00:00"
next_joined_event_duration_in_minutes: 30

Now I am extracting the Start and End times with no issues using the Date\Time formatter node so I am able to output

20:00
21:00

What I like to do is say 2 hours before the output time (in my case force charge a solar battery, I already have the forced charge working).

So at 18:00 the force charge is triggered and then at 19:00 the force charge is stopped. Sounds to me simple. Normally to trigger something at a certain time I could for example use an Inject node, however you canā€™t feed a payload into an Inject node

Essentially what I am trying to achieve is a bit like the inject node, but feed in a time and then trigger a flow at that time.

Your help would be appreciated.

Sounds a bit like an Octopus Energy thing.

Well, clearly you can trigger a flow from the incoming invite to the party. After that there are many ways to do this:

  • Calculate the time difference between ā€˜nowā€™ and ā€˜18:00ā€™ (or two hours before the party start) in milliseconds, and use this to set the variable timer delay in an delay node, which will wait appropriately
  • Make a note of the ā€˜18:00ā€™ time, push it to context, and have another flow checking the current time (use sensor.time from the time date integration) against the saved time, and when equal runs the rest of the flow
  • Use a WebSocket ā€˜wait untilā€™ node (or a ā€˜Trigger nodeā€™) with the condition being the time you want (much like above)
  • Calculate and write the time you want the flow to start to an HA entity (using WebSocket ā€˜Timeā€™ entity perhaps) then use WebSocket ā€˜Timeā€™ trigger node to trigger the flow based on the future time stored in this HA entity
  • Use a service call node to write a calendar event to HA, then use a WebSocket ā€˜Calendar eventā€™ node to trigger when the calendar event starts or ends in HA

There are probably moreā€¦

For myself I would like to stack events like this for Solar PV battery control looking forward a couple of days. Now that we have the Calendar WebSocket node (and it does appear to work) I need to find some time to experiment.

The only thing I would worry about is DST, since some of these event messages are given in UTC, so extracting just the hour may not work during summer time.

Using an inject and Call Service node to create a new calendar event, with date/time in the inject JSON data field. This could easily be automated. Using the Calendar_event node to respond to the start (or end) of the event. Using another Call service node to pull down the current calendar event list.

Really great that now service calls return data!

1 Like

If you are using the time formatter node, set the input type as Etc/UTC and then set your local timezone for the output. It should account for daylight savings.

1 Like

Hi Geoff, This is exactly what it is, an Octopus Power Saving Event.

Essentially all I want to do is Force Charge the battery prior to the event (At Octopus Go itā€™s currently Ā£0.29/kWh) and then discharge it during the event which means typically a Ā£1.75/kWh return.

I did some very rough calculations I think I could end up paying Ā£1.45 roughly to charge the batteries and then see a return of around Ā£8.75 return. +/- convertion losses from DC to AC during export and AC to DC during charging.

Discharging is the easy part as Iā€™ve noticed the binary sensor changes to on when the saving session kicks and then changes to off again once finished.

I do like the sound of your first suggestion and really appreciate your help with this.

Regards Ivan

Geoff,

Ya little beauty. The Calendat Node seems to do the trick perfectly and you can alert on start or end times with an ofset as well which is perfect.

One thing I did find with it and not sure if youā€™ve found the same but you have to set a future event at least 5 minutes in the future before the Calendar Node entry kicks in.

So for example if the time now is 09:30 and I sent an event for 09:32 this doesnā€™t work
However if I set and event for 09:35 this works fine.

Have you found similar?

I ran saver sessions last year with a timed-charge plus manually configured inject nodes to set inverter ā€˜selfā€™ mode (I donā€™t get paid much for export, so just let battery support load).

This year I have been using Bottlecap Daveā€™s excellent integration - this enables NR flow to do the notification, opt-in, and start and stop for me. Good, since I rarely get Octopus notifications of a saver session even though I am signed up for them. The ā€˜round-tripā€™ costs for charge-discharge I estimate at 10p per kWh, of which 6p is battery cycle use, 2p to charge from grid, and 2p to discharge to load. Not even worth charging from solar and dumping my charge on export at my fixed rate of 15p.

I am looking at Flux tariff with a fixed time/price (much easier to work with than Agile) but need to get a better solar forecast and control to be able to decide how to manage solar during the summer. I am working on capturing a year of solar/load data and then modelling different setups and rates before deciding if financially and practically worth the effort.

Then I need a better control system. With a planned timed charge, possible pre-peak top-up, and optional dump to grid (export) this is more complicated, so I would like a system of planned events and conflict management. I have to charge my batteries to full to re-balance the SOC every 3 weeks during winter, so this needs more planning to fully automate into other flows attempting to charge, use solar, and export to grid.

I have been waiting for the calendar to arrive, which needs the new Calendar node and Call Service to return values. I have tested this but it needs more work. Prompted by your message I tested it again, and I was able to add a calendar event just 1 minute before it successfully fired. However, I think the calendar node does a poll at irregular events and it was ā€˜hit and missā€™, so I may consider building something in NR from scratch. The other issue is that is does not seem possible to remove calendar events by service call, and I always like to tidy up afterwards.

Needs much more work, which is probably why there appears to be nothing commercially available to do this for us!

Good luck with your project work

Cheers Geoff,

Yer I found I have to force charge my multiple bateries to 100% every so ofter so they are the same SOC, they have a tendancy to become unbalanced depite it having a BMS, force charging seems to balance them all again.

I am using Bottlecap Daveā€™s auto sign in which is a god send as like you the notifications can be hit and miss, Iā€™ve also signed up to their WhatsApp group where they issue alerts.

Also on further investigation you are right, the polling does seem hit and miss, but I just found if the event is at least 10 minutes in the future and the start and end event is 5 minutes apart it seems to work, I did note the plugin was in Beta for now which is probably something to do with it.

Thanks again for helping me solve an issue.

Hey Geoff,

Do you find the calendar node reliable?

If Iā€™ve set a calendar entry directly in the Google Calendar I find the calendar node does not fire, however if I create an event from HA using Call Service it seems to be more reliable.

Regards Ivan

It has only just been added and is in Beta. I have experimented briefly, and yes it does seem a bit hit and miss.
I did add stuff using a service call, which was both missed and found, even at very short notice. I did add stuff using the HA service call, and that was found.

Without looking at the code, I guess that the node polls all the calendars and looks for things to watch for, then waits for an event from HA. I did notice yesterday the node status briefly prompting that it could not find any events on a second test calendar, when I have not set the node up for that calendar (and it has no events) so I am guessing that the node does a broad sweep to pull down future events from all possible calendars, then keeps an internal log of what to listen out for. What we donā€™t know is how often that happens.

It will be a nice solution, but only if it is reliable.

Certainly adding calendar events using Call service works, and there is always the option to set up an automation in HA based on the calendar event (trigger) and to push something to an HA sensor, which can be picked up by a flow in NR using an Events:state node. Kind of depend on how much you want to experiment!

Certainly found that the status on the Node is misleading, right upto the event it display ā€œNo upcoming eventsā€ then it fired anyway, sometimes the event showed up on the status, like you say its hit and miss.

On the whole itā€™s a handy node to have, I just hope the bugs can be ironed out.

You could create 2 input.datetime helpers, time only, start and finish.

image

Using the time node, you can set an offset to the time set in the helper. Until you get the calendar sorted.

image