openhab: config perms shared between docker / host

This commit is contained in:
theBigBlase 2023-12-17 13:37:42 -05:00
parent a24a3e1694
commit e880a09ba8
24 changed files with 283 additions and 469 deletions

View file

@ -1,38 +0,0 @@
Group Room
Group SmartClothes
Group Sensors
Group:Number:AVG Luminance "average luminosity" (Sensors)
Group:Number:AVG Noise "average noise" (Sensors)
Group Actuators
Group Lights (Actuators)
Group Batteries
Contact room1 "room 1"
// Room fixed devices
Number rfidReader "RFID reader" (Sensors, Room) {channel="rfidReader:device:reader1"}
// smart clothes, mobile devices
Color stripColor "el-wire" <lightbulb> (Lights, SmartClothes) {channel="elwire:0210:ewbridge:strip1"}
Dimmer stripIntensity "el-wire" <lightbulb> (Lights, SmartClothes) {channel="elwire:0210:ewbridge:strip1"}
Color stripColor2 "el-wire" <lightbulb> (Lights, SmartClothes) {channel="elwire:0210:ewbridge:strip2"}
Dimmer stripIntensity2 "el-wire" <lightbulb> (Lights, SmartClothes) {channel="elwire:0210:ewbridge:strip2"}
Switch vibrationPatch "vibration patch" (Actuators, SmartClothes) {channel="vibrationPatch:device:vibration"}
Number luminance "luminance level" (Luminance, Sensors, SmartClothes) {channel=zwave:device:luxmeter:node2:sensor_luminance"}
Number luxmeterBattery "luxmeter battery level" <battery> (Batteries, SmartClothes) {channel="zwave:device:luxmeter:node2:battery-level"}
Number noise "noise level" (Noise, Sensors, SmartClothes) {channel="Channel=“zwave:device:noisemeter:node3:sensor_noise”"}
Number noiseSensorBattery "noise sensor battery level" <battery> (Batteries, SmartClothes) {channel="zwave:device:noisemeter:node3:battery-level"}
// optionnel
Number luminanceWristBand "luminance level" (Sensors, SmartClothes) {channel="zwave:device:wristband:node4:luminance"}
Number noiseWristBand "noise level" (Sensors, SmartClothes) {channel="zwave:device:wristband:node4:luminance"}
Contact gsrWristBand "galvanic skin response level" (Sensors, SmartClothes) {channel=“zwave:device:wristband:node4:galvanicSkinResponse"}
Switch vibrationWristBand "noise level" (Actuators, SmartClothes) {channel="zwave:device:wristband:node4:vibration"}

View file

@ -1,175 +0,0 @@
import org.eclipse.smarthome.model.script.ScriptServiceUtil
// import org.eclipse.smarthome.core.library.items.StringItem
import java.util.HashMap
import java.util.HashSet
val TAG_FileName = "IFT605SmartClothes.rules"
val smartClothesID = "12345678"
var Contact currentRoom
var MQTTBroker currentMQTTBroker
// managing context
var boolean goodConditions = true // of course, only one of good/bad conditions is required
var boolean badConditions = false
var badConditionsStartTime = 0 // in milliseconds
val URGE_TO_CHANGE_ROOM_TIME_TRIGGER = 300000 // 5 minutes
// managing people in the room
var people = new HashSet<String>()
var luminanceMeasures = new HashMap<String, Integer>()
var noiseMeasures = new HashMap<String, Integer>()
// j'entre dans une pièce
val iEnter = [ ContactItem room, String smartClothesID, MQTTBroker broker |
broker.sendCommand(CONNECT);
broker.sendCommand(SUBSCRIBE, "room/1/#");
broker.sendCommand(SUBSCRIBE, "smartclothes/#");
broker.sendCommand(SUBSCRIBE, "room/1/tag/+");
broker.sendCommand(SUBSCRIBE, "smartclothes/+/sensor/luminance");
broker.sendCommand(SUBSCRIBE, "smartclothes/+/sensor/noise");
// informer que l'on vient d'entrer dans la pièce
broker.sendCommand(PUBLISH, smartClothesID+"/status", "Online")
vibrationPatch.sendCommand(OFF)
]
// je sors de une pièce
val iQuit = [ ContactItem room, String smartClothesID, MQTTBroker broker |
broker.sendCommand(UNSUBSCRIBE, "room/1/#");
broker.sendCommand(UNSUBSCRIBE, "smartclothes/#");
broker.sendCommand(UNSUBSCRIBE, "room/1/tag/+");
broker.sendCommand(UNSUBSCRIBE, "smartclothes/+/sensor/luminance");
broker.sendCommand(UNSUBSCRIBE, "smartclothes/+/sensor/noise");
// informer que l'on vient d'entrer dans la pièce
broker.sendCommand(PUBLISH, smartClothesID+"/status", "Offline")
]
// le vêtement entre dans une pièce
val someoneEnterInRoom = [ String smartClothesID |
people.add(smartClothesID)
]
val someoneQuitRoom = [ String smartClothesID |
people.remove(smartClothesID)
noiseMeasures.remove(smartClothesID)
luminanceMeasures.remove(smartClothesID)
]
// fonctions utilitaires pour la gestion du contexte
// autre solutions pour calculer les moyennes, utiliser les HashMap luminanceMeasures et noiseMeasures
val Integer averageLuminance = [ | Luminance.state
]
val Integer averagenoise = [ | Noise.state
]
val boolean checkGoodConditions = [ Integer roomLuminance, Integer roomNoise |
return (LUMINOSITE_MIN < roomLuminance || roomLuminance < LUMINOSITE_MAX)
&& (NIVEAU_SONORE_MIN < roomNoise || roomNoise < NIVEAU_SONORE_MAX)
]
val reactToNewConditions = [ |
goodConditions = checkGoodConditions(averageLuminance(), averageNoise())
badConditions = !goodConditions
if (goodConditions) {
badConditionsStartTime = 0
vibrationPatch.sendCommand(OFF)
// rapprocher l'éclairage de la valeur optimale
if (Luminance.state < LUMOINOSITE_OPTIMALE) {
stripIntensity.sendCommand(INCREASE)
} else {
stripIntensity.sendCommand(DECREASE)
}
} else {
// Éviter de rester trop longtemps dans des conditions défavorables
vibrationPatch.sendCommand(ON)
if (badConditionsStartTime == 0){
badConditionsStartTime = now.getMillis();
}
if (now.getMillis() - badConditionsStartTime > URGE_TO_CHANGE_ROOM_TIME_TRIGGER) {
vibrationPatch.sendCommand(ON)
}
}
]
rule "Démarrage de openHAB"
when
System started
then
logInfo(TAG_FileName, "Rule : Démarrage de openHAB")
currentRoom = room1
currentMQTTBroker = room1MQTT
iEnter(currentRoom, smartClothesID, currentMQTTBroker)
end
// Diffuser les mesures de ses capteurs aux autres vêtements intelligents
rule "lecture d'une mesure de luminosité par le capteur du vêtement"
when
// Item luminance received update
Member of Luminance received update
then
var sensorName = triggeringItem.name
var value = triggeringItem.state
currentMQTTBroker.sendCommand(PUBLISH, "smartclothes/"+smartClothesID+"/sensor/luminance", value)
end
rule "lecture d'une mesure de bruit par le capteur du vêtement"
when
// Item noise received update
Member of Noise received update
then
var sensorName = triggeringItem.name
var value = triggeringItem.state
currentMQTTBroker.sendCommand(PUBLISH, "smartclothes/"+smartClothesID+"/sensor/noise", value)
end
// Gérer son contexte ambiant
rule "nouvelle mesure de bruit publiée par le courtier MQTT"
when currentMQTTBroker "smartclothes/+/sensor/noise" changed
then
noiseMeasures.put(extractID(triggeringItem.newState.topic), trigerringItem.newState.value)
reactToNewConditions()
end
rule "nouvelle mesure de bruit publiée par le courtier MQTT"
when currentMQTTBroker "smartclothes/+/sensor/luminance" changed
then
luminanceMeasures.put(extractID(triggeringItem.newState.topic), trigerringItem.newState.value)
reactToNewConditions()
end
// Tenir compte des arrivées et départs de personnes dans la salle
rule "arrivée d'une personne"
when
// si on n'utilise pas le mécanisme des dernières volontés de MQTT,
// il faut surveiller les éléments pertinents à la main
// currentMQTTBroker "room/+/tag" changed //lecture d'un tag RFID
// or currentMQTTBroker "smartclothes/+/sensor/luminance" changed // member of Luminance changed
// or currentMQTTBroker "smartclothes/+/sensor/noise" changed
currentMQTTBroker "+/status " changed to "Online" //lecture d'un tag RFID
then
String triggeringSmartClothesID = extractID(triggeringItem.newState.topic)
someoneEnterInRoom(triggeringSmartClothesID)
end
// Tenir compte des arrivées et départs de personnes dans la salle
rule "départ d'une personne"
when
currentMQTTBroker "+/status " changed to "Offline" //lecture d'un tag RFID
then
String triggeringSmartClothesID = extractID(triggeringItem.newState.topic)
someoneQuitRoom(triggeringSmartClothesID)
end
rule "Arrêt de openHAB"
when
System shuts down
then
logInfo(TAG_FileName, " Rule : Arrêt de openHAB")
// sauvegarder les états des items et le contexte
iQuit(currentRoom, smartClothesID, currentMQTTBroker)
end

View file

@ -1,62 +0,0 @@
/**
Vêtement intelligent
**/
Bridge elwire:bridge:ewbridge [ ipAddress="192.168.3.123" ] {
// gateway el-wire
Thing 0210 strip1 [stripId="1"] //référer par elwire:0210:ewbridge:strip1
Thing 0220 strip2 [stripId="2"] // référer par elwire:0220:ewbridge:strip2
}
//vibration patch
Thing vibrationPatch:device:vibration "vibration patch" @ "smart clothes"
// voir description à https://www.openhab.org/addons/bindings/zwave/doc/things.html
Bridge zwave:serial_zstick:8c582004 "ZWave Controller" [ port="/dev/ttyACM0", controller_softreset="false", controller_master="true", heal_enable="true", security_networkkey="???" ] {
// ampèremètres placés sur les interrupteurs du plafonnier
Thing luxMeter node2 "luxmeter " @ "smart clothes" [ node_id=2 ] {
Channels:
// sensors
Type number : luminance [ updateInterval=10 ]
Type number : battery-level [ updateInterval=10 ]
}
Thing noiseMeter node3 "noise meter" @ "smart clothes" [ node_id=3 ]
Channels:
// sensors
Type number : noise [ updateInterval=10 ]
Type number : battery-level [ updateInterval=10 ]
Thing wristband node4 "wristBand" @ "smart clothes" [ node_id=4 ] {
Channels:
// sensors
Type number : luminance [ updateInterval=10 ]
Type number : noise [ updateInterval=10 ]
Type string : accelerometer [ updateInterval=10 ]
Type number : speed [ updateInterval=10 ]
Type number : galvanicSkinResponse [ updateInterval=10 ]
// effectors
Type switch : vibration
Type switch : enable
}
}
/**
Pièce
**/
// https://www.smarthomeblog.net/mqtt-openhab/
// https://gist.github.com/davidgraeff/6c00d2ad5e4bc553f5f209118307d8fd
// https://community.openhab.org/t/solved-oh-2-4-mqtt-binding-generic-thing-statetopic-working-commandtopic-not-working/63619
Bridge mqtt:systemBroker:embedded-mqtt-broker [ host="127.0.0.1", secure=false ]
{
Thing mqtt:topic:room1MQTT {
Channels:
Type string : room1 "all MQTT room events" @ "room 1"[ stateTopic="room/1/#" ]
Type string : smartclothes "all MQTT smart clothes events" @ "room 1"[ stateTopic="smartclothes/#" ]
Type switch : tag "RFID MQTT event" @ "room 1" [ stateTopic="room/+/tag"]
Type string : noise "noise MQTT event" @ "room 1" [ stateTopic="smartclothes/+/sensor/noise" ]
Type string : luminance "luminosity MQTT event" @ "room 1" [ stateTopic="smartclothes/+/sensor/luminance" ]
}
}
Thing rfidReader:device:reader1 "rfidReader " @ "room 1"