Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
compact-slowcontrol
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4
Issues
4
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Peter-Bernd Otte
compact-slowcontrol
Commits
530be454
Commit
530be454
authored
Aug 04, 2019
by
Peter-Bernd Otte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update python/relais-control/relais-control.py, python/relais-control/relais.py files
parent
4a04fc18
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
7 deletions
+32
-7
python/relais-control/relais-control.py
python/relais-control/relais-control.py
+5
-1
python/relais-control/relais.py
python/relais-control/relais.py
+27
-6
No files found.
python/relais-control/relais-control.py
View file @
530be454
...
...
@@ -36,6 +36,8 @@ def on_connect(client, userdata, flags, rc):
logger
.
debug
(
"MQTT: "
+
x
.
MQTTname
+
" switchOffTopics subscribed"
)
for
y
in
x
.
inverseSwitchOnTopics
:
client
.
subscribe
(
y
)
logger
.
debug
(
"MQTT: "
+
x
.
MQTTname
+
" inverseSwitchOnTopics subscribed"
)
for
y
in
x
.
prolongateStateTopics
:
client
.
subscribe
(
y
)
logger
.
debug
(
"MQTT: "
+
x
.
MQTTname
+
" prolongateStateTopics subscribed"
)
client
.
subscribe
(
x
.
MQTTname
+
"/set"
)
logger
.
debug
(
"MQTT: Subscribed to all topics"
)
else
:
...
...
@@ -102,12 +104,14 @@ if os.path.exists(args.config_file):
toggleTopics
=
cfg
[
section
][
"toggleTopics"
]
if
"toggleTopics"
in
cfg
[
section
]
else
[]
switchOffTopics
=
cfg
[
section
][
"switchOffTopics"
]
if
"switchOffTopics"
in
cfg
[
section
]
else
[]
inverseSwitchOnTopics
=
cfg
[
section
][
"inverseSwitchOnTopics"
]
if
"inverseSwitchOnTopics"
in
cfg
[
section
]
else
[]
prolongateStateTopics
=
cfg
[
section
][
"prolongateStateTopics"
]
if
"prolongateStateTopics"
in
cfg
[
section
]
else
[]
# print(type(toggleTopics))
if
type
(
defaultTopics
)
is
not
list
:
defaultTopics
=
[
defaultTopics
]
if
type
(
toggleTopics
)
is
not
list
:
toggleTopics
=
[
toggleTopics
]
if
type
(
switchOffTopics
)
is
not
list
:
toggleTopics
=
[
switchOffTopics
]
if
type
(
inverseSwitchOnTopics
)
is
not
list
:
toggleTopics
=
[
inverseSwitchOnTopics
]
if
type
(
prolongateStateTopics
)
is
not
list
:
prolongateStateTopics
=
[
prolongateStateTopics
]
defaultSwitchOffTime
=
cfg
[
section
][
"defaultSwitchOffTime"
]
if
"defaultSwitchOffTime"
in
cfg
[
section
]
else
None
debugItem
=
cfg
[
section
][
"debug"
]
if
"debug"
in
cfg
[
section
]
else
debug
...
...
@@ -115,6 +119,7 @@ if os.path.exists(args.config_file):
relaisList
.
append
(
relais
(
MQTTClient
=
client
,
MQTTName
=
MQTTName
,
MQTTRelaisTopic
=
cfg
[
section
][
"MQTTRelaisTopic"
],
toggleTopics
=
toggleTopics
,
switchOffTopics
=
switchOffTopics
,
defaultTopics
=
defaultTopics
,
inverseSwitchOnTopics
=
inverseSwitchOnTopics
,
prolongateStateTopics
=
prolongateStateTopics
,
defaultSwitchOffTime
=
defaultSwitchOffTime
,
debug
=
debugItem
))
logger
.
info
(
"Adding successfully."
)
...
...
@@ -131,7 +136,6 @@ sleepTime = 1 if args.verbosity>0 else 0.025
while
True
:
for
x
in
relaisList
:
x
.
check
()
# x.relaisMsg(json.loads('{"time": 1564578103.410478, "type": "FSR14", "setv": 1.0, "v": 1.0}'))
time
.
sleep
((
1
-
time
.
time
()
%
1
)
*
sleepTime
)
#every second, even if the processing before took longer
...
...
python/relais-control/relais.py
View file @
530be454
...
...
@@ -21,7 +21,7 @@ class rLightDesire(Enum):
class
relais
:
def
__init__
(
self
,
MQTTClient
,
MQTTName
,
MQTTRelaisTopic
,
defaultTopics
=
None
,
toggleTopics
=
None
,
switchOffTopics
=
None
,
inverseSwitchOnTopics
=
None
,
defaultSwitchOffTime
=
None
,
debug
=
False
):
inverseSwitchOnTopics
=
None
,
prolongateStateTopics
=
None
,
defaultSwitchOffTime
=
None
,
debug
=
False
):
self
.
MQTTname
=
MQTTName
#string
self
.
type
=
"relais"
self
.
debug
=
debug
...
...
@@ -38,6 +38,7 @@ class relais:
self
.
toggleTopics
=
toggleTopics
if
toggleTopics
is
not
None
else
set
()
self
.
switchOffTopics
=
switchOffTopics
if
switchOffTopics
is
not
None
else
set
()
self
.
inverseSwitchOnTopics
=
inverseSwitchOnTopics
if
inverseSwitchOnTopics
is
not
None
else
set
()
self
.
prolongateStateTopics
=
prolongateStateTopics
if
prolongateStateTopics
is
not
None
else
set
()
self
.
v
=
None
# state, the relais should have
self
.
timeLastChange
=
None
# last change of v
...
...
@@ -86,7 +87,7 @@ class relais:
if
msg
[
'v'
]
>
0
:
self
.
lockingPIRs
.
add
(
topic
)
self
.
lightdesire
=
rLightDesire
.
lockedDueToPIR
self
.
setV
(
1
,
reason
=
"PIR
M
otion"
)
self
.
setV
(
1
,
reason
=
"PIR
m
otion"
)
else
:
self
.
lockingPIRs
.
remove
(
topic
)
if
len
(
self
.
lockingPIRs
)
==
0
:
...
...
@@ -95,16 +96,36 @@ class relais:
self
.
publishCurrentStatus
(
reason
=
"last PIR sees no motion"
)
if
self
.
debug
:
print
(
self
.
MQTTname
,
"len(self.lockingPIRs)"
,
len
(
self
.
lockingPIRs
),
"self.lockingPIRs"
,
self
.
lockingPIRs
)
elif
msg
[
'type'
]
in
(
'FRW'
,
'FHF'
,
'FSM60B'
,
'FTK'
,
'FTKE'
):
# smoke detector, window handle, waterleak detector, magnet sensor, handle bar sensor
elif
msg
[
'type'
]
in
(
'FRW'
,
'FHF'
,
'FSM60B'
,
'FTK'
,
'FTKE'
):
# smoke, window handle, waterleak, magnet, handle bar
if
msg
[
'v'
]
>
0
:
self
.
setV
(
1
,
reason
=
"defaultTopics "
+
msg
[
'type'
])
else
:
self
.
setV
(
0
)
self
.
setV
(
0
,
reason
=
"defaultTopics "
+
msg
[
'type'
]
)
elif
msg
[
'type'
]
==
"PTM215"
:
# switches
if
msg
[
'v'
]
>
0
:
self
.
setV
(
1
,
reason
=
"PTM215 pressed down, switch on"
)
# Switch on, if key pressed down
else
:
print
(
self
.
MQTTname
,
"Error: Type not supported for normal actions."
)
print
(
self
.
MQTTname
,
"Error: Type not supported for defaultTopics."
)
for
x
in
self
.
prolongateStateTopics
:
# topics will only prolong the relais state
if
topic
==
x
:
if
self
.
debug
:
print
(
self
.
MQTTname
,
"Prolong Topic:"
,
topic
,
"msg:"
,
msg
)
if
msg
[
'type'
]
in
(
'TFBHSB55'
,
'FBH63'
):
# motion sensors
if
self
.
v
>
0
:
self
.
timeLastStateConfirm
=
time
.
time
()
# to avoid immediate switch off after last PIR
if
msg
[
'v'
]
>
0
:
if
self
.
v
>
0
:
#difference to default behaviour
self
.
lockingPIRs
.
add
(
topic
)
self
.
lightdesire
=
rLightDesire
.
lockedDueToPIR
self
.
publishCurrentStatus
(
reason
=
"PIR motion prolong"
)
else
:
self
.
lockingPIRs
.
remove
(
topic
)
if
self
.
v
>
0
and
len
(
self
.
lockingPIRs
)
==
0
:
self
.
lightdesire
=
rLightDesire
.
stable
self
.
publishCurrentStatus
(
reason
=
"last PIR sees no motion"
)
if
self
.
debug
:
print
(
self
.
MQTTname
,
"Prolong State Topic:"
,
"len(self.lockingPIRs)"
,
len
(
self
.
lockingPIRs
),
"self.lockingPIRs"
,
self
.
lockingPIRs
)
else
:
print
(
self
.
MQTTname
,
"Error: Type not supported for prolongTopics."
)
for
x
in
self
.
toggleTopics
:
# topics do a toggle of the relais
if
topic
==
x
:
if
self
.
debug
:
print
(
self
.
MQTTname
,
"Toggle Topic:"
,
topic
,
"msg:"
,
msg
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment