Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shutter support #101

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Group gThermostat "Main Thermostat" [ "gMainThermostat" ]
Number MainThermostatCurrentTemp "Main Thermostat Current Temperature" (gMainThermostat) [ "CurrentTemperature" ]
Number MainThermostatTargetTemperature "Main Thermostat Target Temperature" (gMainThermostat) [ "TargetTemperature" ]
String MainThermostatHeatingCoolingMode "Main Thermostat Heating/Cooling Mode" (gMainThermostat) [ "homekit:HeatingCoolingMode" ]

Rollershutter BedroomShutter "Bedroom Shutter" <rollershutter> [ "Shutter" ] {mqtt="<[mosquitto:mysensors/SI/1/1/1/0/0:state:default]"}

```

If items are modified in openHAB, a refresh in Mycroft is needed by the command:
Expand Down Expand Up @@ -85,6 +88,7 @@ pip install -r requirements.txt
* "Hey Mycroft, increase Main Thermostat by 1 degrees"
* "Hey Mycroft, what is Main Thermostat is regulated to?"
* "Hey Mycroft, how the Main Thermostat tuned to?"
* "Hey Mycroft, close bedroom shutter"

## Credits
@mortommy
Expand Down
5 changes: 5 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ See the [Hue Emulation](https://www.openhab.org/addons/integrations/hueemulation
Number MainThermostatCurrentTemp "Main Thermostat Current Temperature" (gMainThermostat) ["CurrentTemperature"]
Number MainThermostatTargetTemperature "Main Thermostat Target Temperature" (gMainThermostat) ["TargetTemperature"]
String MainThermostatHeatingCoolingMode "Main Thermostat Heating/Cooling Mode" (gMainThermostat) ["homekit:HeatingCoolingMode"]

Rollershutter BedroomShutter "Bedroom Shutter" <rollershutter> [ "Shutter" ] {mqtt="<[mosquitto:mysensors/SI/1/1/1/0/0:state:default]"}
```

If items are modified in openHAB, a refresh in Mycroft is needed by the voice command:
Expand Down Expand Up @@ -133,6 +135,8 @@ Each item tag supports different command, here is the summary:
| `CurrentHumidity` | what's | humidity |
| | | |
| `CurrentTemperature` | what's | temperature |
| `Shutter` | open | |
| | close | |

With references to the above item definitions, here are an examples of working commands:

Expand All @@ -155,6 +159,7 @@ With references to the above item definitions, here are an examples of working c
- * "Hey Mycroft, increase Main Thermostat by 1 degrees"
- * "Hey Mycroft, what is Main Thermostat is regulated to?"
- * "Hey Mycroft, how the Main Thermostat tuned to?"
- * "Hey Mycroft, close bedroom shutter"

### Additional Comments

Expand Down
39 changes: 36 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self):
#self.currentThermostatItemsDic = dict()
self.targetTemperatureItemsDic = dict()
#self.homekitHeatingCoolingModeDic = dict()
self.shutterItemsDic = dict()

def initialize(self):

Expand Down Expand Up @@ -98,6 +99,9 @@ def initialize(self):
list_items_intent = IntentBuilder("ListItemsIntent").require("ListItemsKeyword").build()
self.register_intent(list_items_intent, self.handle_list_items_intent)

openclose_status_intent = IntentBuilder("OpenClose_StatusIntent").require("Command").require("Item").build()
self.register_intent(openclose_status_intent, self.handle_openclose_status_intent)

self.settings_change_callback = self.handle_websettings_update

def get_config(self, key):
Expand All @@ -121,6 +125,7 @@ def getTaggedItems(self):
self.currentThermostatItemsDic = {}
self.targetTemperatureItemsDic = {}
self.homekitHeatingCoolingModeDic = {}
self.shutterItemsDic = {}

if self.url == None:
LOGGER.error("Configuration needed!")
Expand All @@ -147,6 +152,8 @@ def getTaggedItems(self):
self.targetTemperatureItemsDic.update({json_response[x]['name']: json_response[x]['label']})
elif ("homekit:HeatingCoolingMode" in json_response[x]['tags']):
self.homekitHeatingCoolingModeDic.update({json_response[x]['name']: json_response[x]['label']})
elif ("Shutter" in json_response[x]['tags']):
self.shutterItemsDic.update({json_response[x]['name']: json_response[x]['label']})
else:
pass
else:
Expand Down Expand Up @@ -190,15 +197,15 @@ def handle_list_items_intent(self, message):
msg = msg.strip() + ' ' + self.getItemsFromDict("Current Humidity", self.currentHumItemsDic) + "\n"
msg = msg.strip() + ' ' + self.getItemsFromDict("Thermostat", self.currentThermostatItemsDic) + "\n"
msg = msg.strip() + ' ' + self.getItemsFromDict("Target Temperature", self.targetTemperatureItemsDic) + "\n"
msg = msg.strip() + ' ' + self.getItemsFromDict("Homekit Heating and Cooling", self.homekitHeatingCoolingModeDic)
msg = msg.strip() + ' ' + self.getItemsFromDict("Homekit Heating and Cooling", self.homekitHeatingCoolingModeDic) + "\n"
msg = msg.strip() + ' ' + self.getItemsFromDict("Shutters", self.shutterItemsDic)
self.speak_dialog('FoundItems', {'items': msg.strip()})

def handle_refresh_tagged_items_intent(self, message):
#to refresh the openHAB items labeled list we use an intent, we can ask Mycroft to make the refresh

self.getTaggedItems()
dictLenght = str(len(self.lightingItemsDic) + len(self.switchableItemsDic) + len(self.currentTempItemsDic) + len(self.currentHumItemsDic) + len(self.currentThermostatItemsDic) + len(self.targetTemperatureItemsDic) + len(self.homekitHeatingCoolingModeDic))
self.speak_dialog('RefreshTaggedItems', {'number_item': dictLenght})
dictLenght = str(len(self.lightingItemsDic) + len(self.switchableItemsDic) + len(self.currentTempItemsDic) + len(self.currentHumItemsDic) + len(self.currentThermostatItemsDic) + len(self.targetTemperatureItemsDic) + len(self.homekitHeatingCoolingModeDic) + len(self.shutterItemsDic)) self.speak_dialog('RefreshTaggedItems', {'number_item': dictLenght})

def handle_onoff_status_intent(self, message):
command = message.data.get('Command')
Expand Down Expand Up @@ -228,6 +235,32 @@ def handle_onoff_status_intent(self, message):
LOGGER.error("Item not found!")
self.speak_dialog('ItemNotFoundError')

def handle_openclose_status_intent(self, message):
command = message.data.get('Command')
messageItem = message.data.get('Item')

ohCommand = command
if self.voc_match(command, 'Close'):
ohCommand = "down"
elif self.voc_match(command, 'Open'):
ohCommand = "up"

ohItem = self.findItemName(self.shutterItemsDic, messageItem)

if ohItem != None:
statusCode = self.sendCommandToItem(ohItem, ohCommand.upper())
if statusCode == 200:
self.speak_dialog('OpenClose', {'command': command, 'item': messageItem})
elif statusCode == 404:
LOGGER.error("Some issues with the command execution!. Item not found")
self.speak_dialog('ItemNotFoundError')
else:
LOGGER.error("Some issues with the command execution!")
self.speak_dialog('CommunicationError')
else:
LOGGER.error("Item not found!")
self.speak_dialog('ItemNotFoundError')

def handle_dimmer_status_intent(self, message):
command = message.data.get('DimmerStatusKeyword')
messageItem = message.data.get('Item')
Expand Down
1 change: 1 addition & 0 deletions dialog/de-de/OpenClose.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{command}} {{item}}
1 change: 1 addition & 0 deletions dialog/en-us/OpenClose.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{command}} {{item}}
1 change: 1 addition & 0 deletions regex/de-de/openclose_command.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(?P<Command>öffne|schließe) (?P<Item>.*)
1 change: 1 addition & 0 deletions regex/en-us/openclose_command.rx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(?P<Command>open|close) (?P<Item>.*)
1 change: 1 addition & 0 deletions vocab/de-de/Close.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schließe
1 change: 1 addition & 0 deletions vocab/de-de/Open.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
öffne
2 changes: 2 additions & 0 deletions vocab/de-de/OpenCloseStatusKeyword.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
öffne
schließe
1 change: 1 addition & 0 deletions vocab/en-us/Close.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
close
1 change: 1 addition & 0 deletions vocab/en-us/Open.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
open
2 changes: 2 additions & 0 deletions vocab/en-us/OpenCloseStatusKeyword.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
open
close