From 62e0ced2a43e3ee93379fbab6adb4a1f391da85f Mon Sep 17 00:00:00 2001 From: theBigBlase Date: Thu, 21 Dec 2023 12:08:36 -0500 Subject: [PATCH] update rules / items / things to better reflect project + naming conv. --- .../openhab_conf/items/light_effects.items | 7 ++-- openhab/openhab_conf/rules/battlefield.rules | 42 +++++++++++++++++++ .../openhab_conf/things/battlefield.things | 15 +++---- 3 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 openhab/openhab_conf/rules/battlefield.rules diff --git a/openhab/openhab_conf/items/light_effects.items b/openhab/openhab_conf/items/light_effects.items index 4bf8623..5cc9f0a 100644 --- a/openhab/openhab_conf/items/light_effects.items +++ b/openhab/openhab_conf/items/light_effects.items @@ -4,7 +4,7 @@ Group SmartClothes Group Sensors Group:Number Cam "Last roll" (Sensors) -Group Actuators +Group Actuators Group Lights (Actuators) @@ -12,12 +12,11 @@ Number dmg "dernier degat" (Cam, Sensors){ channel="Channel='mqtt:topic:de'" } - -Switch animation "lampe animation degat" (Lights){ +Switch animation_toggle "toggle animation degat" (Lights){ channel="Channel='mqtt:topic:lumiere'" } -Color couleur "couleur lampe" (Lights){ +String animation "animation degat" (Lights){ channel="Channel='mqtt:topic:lumiere'" } diff --git a/openhab/openhab_conf/rules/battlefield.rules b/openhab/openhab_conf/rules/battlefield.rules new file mode 100644 index 0000000..8c25370 --- /dev/null +++ b/openhab/openhab_conf/rules/battlefield.rules @@ -0,0 +1,42 @@ +import org.eclipse.smarthome.model.script.ScriptServiceUtil +// import org.eclipse.smarthome.core.library.items.StringItem + +val mqttActions = getActions("mqtt", "mqtt:broker:mainBroker") +val TAG_FileName = "battlefield.rules" + + +rule "Démarrage de openHAB" +when + System started +then + logInfo(TAG_FileName, "Rule : Démarrage de openHAB") + // il n'y a personne dans la pièce et l'éclairage est fermé + mqttActions = getActions("mqtt", "mqtt:broker:mainBroker") + + animation_toggle.sendCommand(ON) +end + +rule "light toggle" +when + Item animation_toggle received command +then + logInfo(TAG_FileName, "Rule : mqtt evts") + logInfo(TAG_FileName, "item animation_toggle changed to " + + animation_toggle.state) + + mqttActions.publishMQTT("lumiere/degat/toggle", + animation_toggle.state.toString(), false) +end + + +rule "light animation" +when + Item animation received command +then + logInfo(TAG_FileName, "Rule : mqtt evts") + logInfo(TAG_FileName, "item animation changed to " + + animation.state) + + mqttActions.publishMQTT("lumiere/degat/animation", + animation.state.toString(), false) +end diff --git a/openhab/openhab_conf/things/battlefield.things b/openhab/openhab_conf/things/battlefield.things index aab8bc6..839774e 100644 --- a/openhab/openhab_conf/things/battlefield.things +++ b/openhab/openhab_conf/things/battlefield.things @@ -3,27 +3,24 @@ Bridge mqtt:broker:mainBroker [ host="172.69.1.2", secure=false ] Thing mqtt:topic:lumiere "lumiere" (mqtt:broker:mainBroker) { Channels: - Type switch : light "indicateur degat" [ - stateTopic="lumiere/degat/etat", - commandTopic="lumiere/degat/commande", - on="ON", off="OFF" + Type string : light "indicateur degat animation" [ + stateTopic="lumiere/degat/animation" ] - Type color : light "effect color" [ - stateTopic="lumiere/degat/color/etat", - commandTopic="lumiere/degat/color/commande", colorMode="RGB" + Type switch : light_toggle "indicateur degat toggle" [ + stateTopic="lumiere/degat/toggle" ] } Thing mqtt:topic:de "lecteur de" (mqtt:broker:mainBroker) { Channels: Type number : de "effecteur degat" [ - stateTopic="de/degat/dernierLance" + stateTopic="capteur/de/degat/dernierLance" ] } Thing mqtt:topic:button "recommencer" (mqtt:broker:mainBroker) { Channels: Type switch : de "effecteur nouveau tour" [ - stateTopic="de/nouveauTour" + stateTopic="capteur/boutton/nouveauTour" ] }