I would like some input on the smartest way to do the following.
I have 4 different states we can call them A, B, C and D.
My states should run in a loop of 4 hours interval
In case of state A I would like a switch do the following
3 hours on and 1 hour off
In case of state B I would like my switch to do the following:
2 hours on and 2 hours off
and so on for the last two states.
What is the smartest way to set this up?
hmmmm...what is your intend on how to switch between the four states...i.e. on a timely schedule or totally random, like from an external trigger or how else?
In case of A i would like to have the switch turned on the first hour and then off the next 3 hours.
in case of B the switch is turned of the first two hours and then off the next two hours.
In case of C, 3 hours on and 1 hour off.
Ok, so checking:
You have 1 input.
There are 4 states that are determined from the input.
It is a 4 hour interval.
Ok, as it has been mentioned there is a timing problem, sort of.
Here's my take.
inject node set to inject (output) a signal every 4 hours to get the input reading.
Though this may not make sense at this stage; you need to make a time line when/how things happen.
So, the inject node gets the input value.
That will need a bit of work, but let's keep things simple.
The readings range from 1 to 4.
Put a switch node to switch (route?) the payload depending on the value.
If ==1 send it to a trigger node.
The trigger node will be set to send on then after 3 hours send off
If ==2 make the trigger node make the values 2 and 2. (Similar to 1)
And so on.
Does that help?
I can knock up a basic flow if you want. But understand that it will be limited to a 1-4 input.
Well, yes...this is quite clear from your first post, already.
What I asked is, in what sequence are A, B C and D are "fired" ?.
The "outside loop", so to say, like 16hrs, 4hrs each in a sequence of A,C,D,B, then again A,C,D,B, ...and so on over and over again ?
Instead of three states, like in a traffic light, you have your four States, triggered hourly.
Each state will follow its own sequence, where each hour event will determine if a state change will occur.
The first DSM node, driving the "four state traffic light", will be responsible for driving/controlling the outer-sequence/loop of A,C,D,B
The loop is 4 hours. Within that loop only one state can happend. And the state that happens must take 4 hours. Right now I have use the looptimer node as trigger. This triggers a http request that finds the state value and then one of the 4 states much run for 4 hours.
Yes that helps a lot. Thanks for this. Could you also help me to understand how to setup this flow in home assistant. The trigger to start my flow should be when Home assistants starts as default. I would like to have a "button" in the overview dashboard where I can disable and enable the flow. In my current setup I have looptimer node (value 4 hours interval) that start a trigger which do a http request that determines the value of the State and then determines the range from 1-4.
The only way I know how to start the looptimer is inject node I trigger manually. I guess this is not the way to do this as I have to go to the node red menu to trigger this.
I have seen some use a http request on HACS server start, but is this the best way?
...I don't know Home Assistant, but based on this: home-assistant.io/docs/mqtt/ it can integrate with a MQTT-Broker. Do you already have one, or are able to install one in your setup?