Replies: 5 comments 1 reply
-
Hi @mniemotka, let's see if I get this right. I make some assumptions here so please correct me if that's not correct: There are 5 events:
and two objects with states ON and OFF: the pump and the switch. (and a third if your timetable/calendar is represented as two states, SCHEDULED_ON and SCHEDULED_OFF) What should happen:
|
Beta Was this translation helpful? Give feedback.
-
Appreciate the reply.....I don't know if I can attach a picture or not, but there a couple of things to correct, so see below
scheduled_on - pump should be ON based on the schedulescheduled_off - pump should be OFF based on the schedulepump_override_on - pump should be OFF based on the schedule, BUT the GUI button was pressed which turns it ONpump_override_off - pump should be ON based on the schedule, BUT the GUI button was pressed which turns it OFF
3_way_switch_override_on - pump should be OFF based on the schedule, BUT the physical switch was flipped which turns it ON
3_way_switch_override_off - pump should be ON based on the schedule, BUT the physical switch was flipped which turns it OFF
where is gets complicated is that I "think" I need to also capture the other unique states where the condition of the GUI button has to be considered
double_override_on - pump should be ON based on schedule, BUT the GUI button was pressed, which would turn the pump OFF, but the physical switch was flipped, which turned up pump back ON (The order of what happens first, button press or physical switch flip, I don't think matters????)
double_override_off - pump should be OFF based on schedule, BUT the GUI button was pressed, which would turn the pump ON, but the physical switch was flipped, which turned up pump back OFF (The order of what happens first, button press or physical switch flip, I don't think matters????)
The physical switch is a 3 way switch, and when wired to the relay that controls the pump, it created essential 2 3-way switches. So like in a hallway in your house where you have a switch on either end of the hall, and both can control the light.
The GUI button serves 2 purposes: 1- shows the state of the pump (is it on or off) and 2- can be pressed to change the pump from on to off or off to on.
I have electronics so I can monitor if the pump is receiving power, and that voltage is read on an GPIO pin on my raspberry pi, so it can act an as interrupt. I was thinking this would be the best way to know if the physical switch was used to either turn on the pump when it should have been off, OR to turn off the pump when it should have been on
I hope that helps? It just seems like logically I have it correct, but I am wondering if I can try to get a state diagram to print out for my model, to confirm if I have all the transitions correct.
Any help would be appreciated
Mike
On Friday, May 10, 2024 at 04:28:04 AM CDT, Alexander Neumann ***@***.***> wrote:
Hi @mniemotka,
let's see if I get this right. I make some assumptions here so please correct me if that's not right:
There are 5 events:
- scheduled_on -- when the pump should turn on based on your schedule
- scheduled_off -- when the pump should turn off based on your schedule
- switch_on -- when you flip the switch to ON position
- switch_off -- when you flip the switch to OFF position
- button_pressed -- when you click the GUI button
and two objects with states: the pump and the switch.
What should happen:
- scheduled_on should turn the pump on IF switch is ON
- switch_on should turn the pump on IF it is scheduled to be on
- button_pressed should turn the pump on IF if it is OFF and the switch is ON
- button_pressed should turn the pump off IF if it is ON
- scheduled_off and switch_off should turn the pump off
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
You could use from transitions.extensions import HierarchicalGraphMachine
states = [
{"name": "PumpON", "states": ["SwitchOFF", "SwitchON"], "initial": "SwitchOFF"},
{"name": "PumpOFF", "states": ["SwitchOFF", "SwitchON"], "initial": "SwitchOFF"},
]
transitions = [
["button_pressed", "PumpON_SwitchOFF", "PumpOFF_SwitchOFF"],
["button_pressed", "PumpON_SwitchON", "PumpOFF_SwitchON"],
["button_pressed", "PumpOFF_SwitchOFF", "PumpON_SwitchOFF"],
["button_pressed", "PumpOFF_SwitchON", "PumpON_SwitchON"],
["button_switched", "PumpON_SwitchOFF", "PumpOFF_SwitchON"],
["switch_toggled", "PumpOFF_SwitchOFF", "PumpON_SwitchON"],
["switch_toggled", "PumpON_SwitchOFF", "PumpOFF_SwitchON"],
["switch_toggled", "PumpOFF_SwitchON", "PumpON_SwitchOFF"],
["switch_toggled", "PumpON_SwitchON", "PumpOFF_SwitchOFF"],
]
m = HierarchicalGraphMachine(states=states, transitions=transitions, auto_transitions=False, initial="PumpOFF")
m.get_graph().draw("state_machine.png", prog="dot") |
Beta Was this translation helpful? Give feedback.
-
I just updated transitions-gui which could be useful to integrate a machine view into your GUI: PreviewCodefrom transitions_gui import NestedWebMachine
import time
import logging
logging.basicConfig(level=logging.INFO)
states = [
{"name": "PumpON", "states": ["SwitchOFF", "SwitchON"], "initial": "SwitchOFF"},
{"name": "PumpOFF", "states": ["SwitchOFF", "SwitchON"], "initial": "SwitchOFF"},
]
transitions = [
["button_pressed", "PumpON_SwitchOFF", "PumpOFF_SwitchOFF"],
["button_pressed", "PumpON_SwitchON", "PumpOFF_SwitchON"],
["button_pressed", "PumpOFF_SwitchOFF", "PumpON_SwitchOFF"],
["button_pressed", "PumpOFF_SwitchON", "PumpON_SwitchON"],
["button_switched", "PumpON_SwitchOFF", "PumpOFF_SwitchON"],
["button_switched", "PumpOFF_SwitchOFF", "PumpON_SwitchON"],
["switch_toggled", "PumpOFF_SwitchOFF", "PumpON_SwitchON"],
["switch_toggled", "PumpON_SwitchOFF", "PumpOFF_SwitchON"],
["switch_toggled", "PumpOFF_SwitchON", "PumpON_SwitchOFF"],
["switch_toggled", "PumpON_SwitchON", "PumpOFF_SwitchOFF"],
]
# we need some styling to prevent overlapping in the middle
style = [
{"selector": "edge",
"css": {"font-size": 14}},
{"selector": "edge[source *= 'SwitchOFF'][target *= 'SwitchON']",
"css": {"label": "", "source-label": "data(label)", "source-text-offset": 100}},
{"selector": "edge[source *= 'SwitchON'][target *= 'SwitchOFF']",
"css": {"label": "", "source-label": "data(label)", "source-text-offset": 100}}
]
m = NestedWebMachine(states=states, transitions=transitions, auto_transitions=False, initial="PumpOFF",
name="Pump Controller", graph_css=style)
try:
while True:
time.sleep(1)
except BaseException:
m.stop_server() Again, this is not the correct configuration but (hopefully) is a good point of departure. |
Beta Was this translation helpful? Give feedback.
-
Thanks so much! I will spend the long weekend checking this out!
Mike
On Friday, May 24, 2024 at 08:27:38 AM CDT, Alexander Neumann ***@***.***> wrote:
I just updated transitions-gui which could be useful to integrate a machine view into your GUI:
Preview
pump_controller.png (view on web)
Code
from transitions_gui import NestedWebMachine
import time
import logging
logging.basicConfig(level=logging.INFO)
states = [
{"name": "PumpON", "states": ["SwitchOFF", "SwitchON"], "initial": "SwitchOFF"},
{"name": "PumpOFF", "states": ["SwitchOFF", "SwitchON"], "initial": "SwitchOFF"},
]
transitions = [
["button_pressed", "PumpON_SwitchOFF", "PumpOFF_SwitchOFF"],
["button_pressed", "PumpON_SwitchON", "PumpOFF_SwitchON"],
["button_pressed", "PumpOFF_SwitchOFF", "PumpON_SwitchOFF"],
["button_pressed", "PumpOFF_SwitchON", "PumpON_SwitchON"],
["button_switched", "PumpON_SwitchOFF", "PumpOFF_SwitchON"],
["button_switched", "PumpOFF_SwitchOFF", "PumpON_SwitchON"],
["switch_toggled", "PumpOFF_SwitchOFF", "PumpON_SwitchON"],
["switch_toggled", "PumpON_SwitchOFF", "PumpOFF_SwitchON"],
["switch_toggled", "PumpOFF_SwitchON", "PumpON_SwitchOFF"],
["switch_toggled", "PumpON_SwitchON", "PumpOFF_SwitchOFF"],
]
style = [
{"selector": "edge",
"css": {"font-size": 14}},
{"selector": "edge[source *= 'SwitchOFF'][target *= 'SwitchON']",
"css": {"label": "", "source-label": "data(label)", "source-text-offset": 100}},
{"selector": "edge[source *= 'SwitchON'][target *= 'SwitchOFF']",
"css": {"label": "", "source-label": "data(label)", "source-text-offset": 100}}
]
m = NestedWebMachine(states=states, transitions=transitions, auto_transitions=False, initial="PumpOFF",
name="Pump Controller", graph_css=style)
try:
while True:
time.sleep(1)
except BaseException:
m.stop_server()
Again, this is not the correct configuration but (hopefully) is a good point of departure.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
So I will do my best to describe what I need help with. I have a solar pool heater controller that I designed, and I can schedule when the pool pumps turns on and off with my program. I have a GUI, so there is a button that I can use to manually turn the pump on, OR, it if it on because of schedule, pressing that button will turn it off. The power goes thru a relay.
Last year, I added a second physical swtich, which now essentially in combination with the relay, makes it like having 2 3way switches in your house for a light.
I thought I had it modelled corrected for the transistions, but it seem like it does not act correctly. So as an example:
Schedule says to be ON, but I flip the physical switch, I want the pump to turn off
Schedule says to be ON, but I pressed the SW switch, so pump will be off, but then if I flip the physical switch, it should be back ON
I have states defined for all the possible variations, but not sure if that is the best way?
Any help would be appreciated
Beta Was this translation helpful? Give feedback.
All reactions