Skip to content

Commit

Permalink
add svt-15 support
Browse files Browse the repository at this point in the history
  • Loading branch information
raxers committed Feb 20, 2021
1 parent 0bed5b2 commit 660a69a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/*
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Elehant Water Sensor SVD-15 for Home Assistant
# Elehant Water Sensor SVD-15 and SVT-15 for Home Assistant

[![hacs_badge](https://img.shields.io/badge/HACS-Custom-orange.svg)](https://github.com/custom-components/hacs)
[![Donate](https://img.shields.io/badge/donate-Yandex-red.svg)](https://money.yandex.ru/to/41001371678546)

# Компонент интеграции счетчиков воды Элехант СВД-15 с Home Assistant.
# Компонент интеграции счетчиков воды Элехант СВД-15 и СВТ-15 с Home Assistant.
Для интеграции требуется наличие Bluetooth модуля в сервере HA.

**Установка**
Expand All @@ -15,16 +15,19 @@ sensor:
- platform: elehant_water
scan_duration: 10
scan_interval: 30
mmeasurement: l
measurement: l
devices:
- id: 31560
name: "Вода Горячая Ванная"
- id: 31561
name: "Вода Холодная Кухня"
- id: 31562
name: "Вода Горячая Кухня"
- id: 31563
name: "Вода Холодная Ванная"
# Для двухтарифных счетчиков номера надо указывать через подчеркивание и в кавычках
# Под первой записью укажите так же название для датчика температуры
- id: '31562_1'
name: "Вода Горячая Кухня 1"
name_temp: "Температура воды Кухня"
- id: '31562_2'
name: "Вода Горячая Кухня 2"
```
Где:
Expand Down
69 changes: 65 additions & 4 deletions custom_components/elehant_water/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from homeassistant.helpers.event import async_track_time_interval
import random
import logging
from homeassistant.const import (VOLUME_LITERS, STATE_UNKNOWN, VOLUME_CUBIC_METERS)
from homeassistant.const import (VOLUME_LITERS, STATE_UNKNOWN,
VOLUME_CUBIC_METERS, TEMP_CELSIUS)

_LOGGER = logging.getLogger(__name__)
inf={}
Expand All @@ -31,10 +32,27 @@ def my_process(data):
payload = payload[1].val
c_num = int.from_bytes(payload[6:8], byteorder='little')
c_count = int.from_bytes(payload[9:12], byteorder='little')
if measurement == 'm3':
inf[c_num] = c_count/10000
else:
inf[c_num] = c_count/10
if (str(mac).find('b0:03:02') !=-1) or (str(mac).find('b0:04:02') !=-1):
manufacturer_data = ev.retrieve("Manufacturer Specific Data")
payload = manufacturer_data[0].payload
payload = payload[1].val
c_num = int.from_bytes(payload[6:8], byteorder='little')
if str(mac).find('b0:03:02') !=-1:
c_num = str(c_num)+'_1'
else:
c_num = str(c_num)+'_2'
c_count = int.from_bytes(payload[9:12], byteorder='little')
c_temp = int.from_bytes(payload[14:16], byteorder='little')/100
inf[c_num.split('_')[0]] = c_temp
if measurement == 'm3':
inf[c_num] = c_count/10000
else:
inf[c_num] = c_count/10

start = time.time()
event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(event_loop)
Expand All @@ -61,17 +79,60 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
scan_interval = config['scan_interval']
scan_duration = config['scan_duration']
measurement = config.get('measurement')
for device in config['devices']:
ha_entities.append(ExampleSensor(device['id'],device['name']))
for device in config['devices']:
ha_entities.append(WaterSensor(device['id'],device['name']))
if '_1' in str(device['id']):
ha_entities.append(WaterTempSensor(device['id'].split('_')[0], device['name_temp']))
inf[device['id'].split('_')[0]]=STATE_UNKNOWN
inf[device['id']]=STATE_UNKNOWN
add_entities(ha_entities, True)
async_track_time_interval(
hass, update_counters, scan_interval
)

class WaterTempSensor(Entity):
"""Representation of a Sensor."""

def __init__(self,counter_num, name):
"""Initialize the sensor."""
self._state = None
self._name = name
self._state = STATE_UNKNOWN
self._num = counter_num

@property
def name(self):
"""Return the name of the sensor."""
return self._name

@property
def state(self):
"""Return the state of the sensor."""
return self._state

@property
def unit_of_measurement(self):
"""Return the unit of measurement."""

return TEMP_CELSIUS

@property
def icon(self):
"""Return the unit of measurement."""
return 'mdi:thermometer-lines'
@property
def unique_id(self):
"""Return Unique ID """
return 'elehant_temp_'+str(self._num)

def update(self):
"""Fetch new state data for the sensor.
This is the only method that should fetch new data for Home Assistant.
"""
# update_counters()
self._state = inf[self._num]

class ExampleSensor(Entity):
class WaterSensor(Entity):
"""Representation of a Sensor."""

def __init__(self,counter_num, name):
Expand Down

0 comments on commit 660a69a

Please sign in to comment.