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

manage garage as a cover instead of switch (without koleos docs) (#197) #199

Open
wants to merge 2 commits into
base: master
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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# tydom2MQTT

![Docker pulls](https://img.shields.io/docker/pulls/fmartinou/tydom2mqtt)
![License](https://img.shields.io/github/license/fmartinou/tydom2mqtt)
![Travis](https://img.shields.io/travis/fmartinou/tydom2mqtt/master)

![](docs/tydom2mqtt_logo_250.png)

> **Deltadore Tydom to MQTT Bridge**

## Ready to go?
### Check out the [documentation](https://fmartinou.github.io/tydom2mqtt/) to get started!

## Contact & Support

- Create a [GitHub issue](https://github.com/fmartinou/tydom2mqtt/issues) for bug reports, feature requests, or questions
- Add a ⭐️ [star on GitHub](https://github.com/fmartinou/tydom2mqtt) to support the project!

## Developer guide
[Please find here the developer guide](DEV.md)

## Changelog
[Please find here the changelog](docs/changelog/README.md)

## License

This project is licensed under the [MIT license](https://github.com/fmartinou/tydom2mqtt/blob/master/LICENSE).
36 changes: 36 additions & 0 deletions app/mqtt/MqttClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
from sensors.Alarm import Alarm
from sensors.Boiler import Boiler
from sensors.Cover import Cover
from sensors.Garage import Garage
from sensors.Light import Light
from sensors.Switch import Switch
from sensors.ShHvac import ShHvac
from sensors.AutomaticDoor import AutomaticDoor

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -141,6 +143,29 @@ async def on_message(self, client, topic, payload, qos, properties):
device_id = (get_id.split("_"))[0]
endpoint_id = (get_id.split("_"))[1]
await Cover.put_position(tydom_client=self.tydom, device_id=device_id, cover_id=endpoint_id, position=str(value))

elif 'set_garageLevelCmd' in str(topic):
value = payload.decode()
logger.info(
'set_garageLevelCmd message received (topic=%s, message=%s)',
topic,
value)
get_id = (topic.split("/"))[2]
device_id = (get_id.split("_"))[0]
endpoint_id = (get_id.split("_"))[1]
await Garage.put_garage_positionCmd(tydom_client=self.tydom, device_id=device_id, cover_id=endpoint_id,
positionCmd=str(value))

elif ('set_garageLevel' in str(topic)) and not ('set_garageLevelCmd' in str(topic)):
value = json.loads(payload)
logger.info(
'set_garageLevel message received (topic=%s, message=%s)',
topic,
value)
get_id = (topic.split("/"))[2]
device_id = (get_id.split("_"))[0]
endpoint_id = (get_id.split("_"))[1]
await Garage.put_garage_position(tydom_client=self.tydom, device_id=device_id, cover_id=endpoint_id, position=str(value))

elif 'set_tilt' in str(topic):
value = json.loads(payload)
Expand Down Expand Up @@ -176,6 +201,17 @@ async def on_message(self, client, topic, payload, qos, properties):
endpoint_id = (get_id.split("_"))[1]
await Light.put_level(tydom_client=self.tydom, device_id=device_id, light_id=endpoint_id,
level=str(value))

elif 'open_automatic_door' in str(topic):
value = payload.decode()
logger.info(
'open_automatic_door message received (topic=%s, message=%s)',
topic,
value)
get_id = (topic.split("/"))[2]
device_id = (get_id.split("_"))[0]
endpoint_id = (get_id.split("_"))[1]
await AutomaticDoor.put_podPosition(tydom_client=self.tydom, device_id=device_id, door_id=endpoint_id, position='OPEN')

elif ('set_alarm_state' in str(topic)) and not ('homeassistant' in str(topic)):
value = payload.decode()
Expand Down
89 changes: 89 additions & 0 deletions app/sensors/AutomaticDoor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import json
import logging

from .Sensor import Sensor

logger = logging.getLogger(__name__)
button_config_topic = "homeassistant/button/tydom/{id}/config"
button_state_topic = "button/tydom/{id}/state"
button_command_topic = "button/tydom/{id}/open_automatic_door"

class AutomaticDoor:

def __init__(self, tydom_attributes, tydom_client=None, mqtt=None):

self.config_topic = None
self.topic_to_func = None
self.config = None
self.device = None
self.attributes = tydom_attributes
self.device_id = self.attributes['device_id']
self.endpoint_id = self.attributes['endpoint_id']
self.id = self.attributes['id']
self.name = self.attributes['name']
self.mqtt = mqtt
self.tydom_client = tydom_client

async def setup(self):
self.config = {}
self.device = {
'manufacturer': 'Delta Dore',
'name': self.name,
'model': 'Automatic Door',
'identifiers': self.id,
}
self.config['device'] = self.device

self.config_topic = button_config_topic.format(id=self.id)
self.config = {
'name': None, # set an MQTT entity's name to None to mark it as the main feature of a device
'unique_id': self.id,
'device': self.device,
'button_state_topic': button_state_topic.format(id=self.id),
'command_topic': button_command_topic.format(id=self.id),
'icon': "mdi:lock-open-outline",
'availability_topic': button_state_topic.format(id=self.id),
'availability_template': '{% if value_json.podPosition == "CLOSE" -%}online{%- else -%}offline{%- endif %}',
'payload_press': "OPEN"
}
if self.mqtt is not None:
self.mqtt.mqtt_client.publish(
self.config_topic, json.dumps(
self.config), qos=0, retain=True)

async def update(self):
await self.setup()

try:
await self.update_sensors()
except Exception as e:
logger.error("AutomaticDoor sensors Error :")
logger.error(e)

if self.mqtt is not None:
self.mqtt.mqtt_client.publish(
self.config['button_state_topic'],
self.attributes,
qos=0,
retain=True)

logger.info(
"AutomaticDoor created / updated : %s %s",
self.name,
self.id)

async def update_sensors(self):
for i, j in self.attributes.items():
if not i == 'device_type' and not i == 'id' and not i == 'device_id' and not i == 'endpoint_id':
new_sensor = Sensor(
elem_name=i,
tydom_attributes_payload=self.attributes,
mqtt=self.mqtt)
await new_sensor.update()

@staticmethod
async def put_podPosition(tydom_client, device_id, door_id, position):
logger.info("put_podPosition: %s to %s", device_id, position)
if not (position == ''):
# ex: 'podPosition': 'OPEN'
await tydom_client.put_devices_data(device_id, door_id, 'podPosition', position)
127 changes: 127 additions & 0 deletions app/sensors/Garage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import json
import logging
from .Sensor import Sensor

logger = logging.getLogger(__name__)
cover_command_topic = "cover/tydom/{id}/set_garageLevelCmd"
cover_config_topic = "homeassistant/cover/tydom/{id}/config"
cover_position_topic = "cover/tydom/{id}/current_position"
cover_state_topic = "cover/tydom/{id}/state"
cover_level_topic = "cover/tydom/{id}/current_level"
cover_set_level_topic = "cover/tydom/{id}/set_garageLevel"
cover_attributes_topic = "cover/tydom/{id}/attributes"


class Garage:
def __init__(self, tydom_attributes, set_level=None, mqtt=None):
self.device = None
self.config = None
self.config_topic = None
self.attributes = tydom_attributes
self.device_id = self.attributes['device_id']
self.endpoint_id = self.attributes['endpoint_id']
self.id = self.attributes['id']
self.name = self.attributes['cover_name']
try:
self.current_level = self.attributes['level']
except Exception as e:
logger.error(e)
self.current_level = None

self.set_level = set_level
self.current_position = set_level

if 'position' in tydom_attributes:
self.current_position = self.attributes['position']


self.mqtt = mqtt

async def setup(self):
self.device = {
'manufacturer': 'Delta Dore',
'model': 'Garage Door Horizontal',
'name': self.name,
'identifiers': self.id}
self.config_topic = cover_config_topic.format(id=self.id)
self.config = {
'name': None, # set an MQTT entity's name to None to mark it as the main feature of a device
'unique_id': self.id,
'command_topic': cover_command_topic.format(
id=self.id),
'position_topic': cover_position_topic.format(
id=self.id),
'level_topic': cover_level_topic.format(
id=self.id),
'set_position_topic': cover_set_level_topic.format(
id=self.id),
'payload_open': "ON",
'payload_close': "OFF",
'payload_stop': "STOP",
'retain': 'false',
'device': self.device,
'device_class': self.attributes['cover_class']}

self.config['json_attributes_topic'] = cover_attributes_topic.format(
id=self.id)

if self.mqtt is not None:
self.mqtt.mqtt_client.publish(
self.config_topic, json.dumps(
self.config), qos=0, retain=True)

async def update(self):
await self.setup()

try:
await self.update_sensors()
except Exception as e:
logger.error("GarageDoor Horizontal sensors Error :")
logger.error(e)

self.level_topic = cover_state_topic.format(
id=self.id, current_level=self.current_level)

if self.mqtt is not None:
#and 'position' in self.attributes:
self.mqtt.mqtt_client.publish(
self.config['position_topic'],
self.current_level,
qos=0, retain=True)

if self.mqtt is not None:
self.mqtt.mqtt_client.publish(
self.level_topic,
self.current_level,
qos=0,
retain=True)
self.mqtt.mqtt_client.publish(
self.config['json_attributes_topic'],
self.attributes,
qos=0,
retain=True)

logger.info(
"GarageDoor Horizontal created / updated : %s %s %s",
self.name,
self.id,
self.current_level)

async def update_sensors(self):
for i, j in self.attributes.items():
if not i == 'device_type' and not i == 'id' and not i == 'device_id' and not i == 'endpoint_id':
new_sensor = Sensor(
elem_name=i,
tydom_attributes_payload=self.attributes,
mqtt=self.mqtt)
await new_sensor.update()

async def put_garage_position(tydom_client, device_id, cover_id, position):
logger.info("%s %s %s", cover_id, 'level', position)
if not (position == ''):
await tydom_client.put_devices_data(device_id, cover_id, 'level', position)

async def put_garage_positionCmd(tydom_client, device_id, cover_id, positionCmd):
logger.info("%s %s %s", cover_id, 'levelCmd', positionCmd)
if not (positionCmd == ''):
await tydom_client.put_devices_data(device_id, cover_id, 'levelCmd', positionCmd)
6 changes: 5 additions & 1 deletion app/sensors/Sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, elem_name, tydom_attributes_payload, mqtt=None):
# extracted from json, but it will make sensor not in payload to be
# considered offline....
self.parent_device_id = str(tydom_attributes_payload['id'])
self.parent_name = str(tydom_attributes_payload['name'])
self.id = elem_name + '_tydom_' + str(tydom_attributes_payload['id'])
self.name = elem_name
if 'device_class' in tydom_attributes_payload.keys():
Expand Down Expand Up @@ -106,7 +107,10 @@ def __init__(self, elem_name, tydom_attributes_payload, mqtt=None):
async def setup(self):
self.device = {
'manufacturer': 'Delta Dore',
'identifiers': self.parent_device_id}
'identifiers': self.parent_device_id,
'model':'Sensor',
'name':self.parent_name
}

self.config_sensor_topic = sensor_config_topic.format(id=self.id)

Expand Down
Loading