Merge pull request #1 from lolouk44/MQTT_Discovery
Mqtt discovery, Docker Image
This commit is contained in:
commit
5944cdbbae
@ -1,3 +1,9 @@
|
|||||||
|
## [0.1.6] - 2020-07-01
|
||||||
|
### Added
|
||||||
|
- Docker Image so install is quicker (no local build required).
|
||||||
|
## [0.1.5] - 2020-07-01
|
||||||
|
### Added
|
||||||
|
- MQTT Discovery Support.
|
||||||
## [0.1.4] - 2020-06-29
|
## [0.1.4] - 2020-06-29
|
||||||
### Added
|
### Added
|
||||||
- First release (version in line with non Add-On script for ease of maintenance).
|
- First release (version in line with non Add-On script for ease of maintenance).
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
FROM python:3.8-slim
|
FROM python:3.8-slim
|
||||||
|
LABEL io.hass.version="0.1.6" io.hass.type="addon" io.hass.arch="armhf|aarch64|i386|amd64"
|
||||||
WORKDIR /opt/miscale
|
WORKDIR /opt/miscale
|
||||||
COPY src /opt/miscale
|
COPY src /opt/miscale
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "Xiaomi Mi Scale",
|
"name": "Xiaomi Mi Scale",
|
||||||
"version": "0.1.3",
|
"version": "0.1.6",
|
||||||
"slug": "xiaomi_mi_scale",
|
"slug": "xiaomi_mi_scale",
|
||||||
"description": "Read weight measurements from Xiamomi scale via BLE",
|
"description": "Read weight measurements from Xiamomi scale via BLE",
|
||||||
"url": "https://github.com/lolouk44/xiaomi_mi_scale_ha_add_on",
|
"url": "https://github.com/lolouk44/xiaomi_mi_scale_ha_add_on",
|
||||||
|
"image": "lolouk44/xiaomi-mi-scale",
|
||||||
"arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
|
"arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
|
||||||
"startup": "before",
|
"startup": "before",
|
||||||
"boot": "auto",
|
"boot": "auto",
|
||||||
@ -20,6 +21,8 @@
|
|||||||
"MQTT_PASSWORD": "",
|
"MQTT_PASSWORD": "",
|
||||||
"MQTT_PORT": 1883,
|
"MQTT_PORT": 1883,
|
||||||
"TIME_INTERVAL": 30,
|
"TIME_INTERVAL": 30,
|
||||||
|
"MQTT_DISCOVERY": true,
|
||||||
|
"MQTT_DISCOVERY_PREFIX": "homeassistant",
|
||||||
|
|
||||||
"USER1_GT": 70,
|
"USER1_GT": 70,
|
||||||
"USER1_SEX": "male",
|
"USER1_SEX": "male",
|
||||||
@ -48,6 +51,8 @@
|
|||||||
"MQTT_PASSWORD": "str",
|
"MQTT_PASSWORD": "str",
|
||||||
"MQTT_PORT": "int",
|
"MQTT_PORT": "int",
|
||||||
"TIME_INTERVAL": "int",
|
"TIME_INTERVAL": "int",
|
||||||
|
"MQTT_DISCOVERY": "bool",
|
||||||
|
"MQTT_DISCOVERY_PREFIX": "str",
|
||||||
|
|
||||||
"USER1_GT": "int",
|
"USER1_GT": "int",
|
||||||
"USER1_SEX": "str",
|
"USER1_SEX": "str",
|
||||||
|
@ -29,20 +29,15 @@ try:
|
|||||||
sys.stdout.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Loading Config From Add-On Options...\n")
|
sys.stdout.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Loading Config From Add-On Options...\n")
|
||||||
data = json.load(json_file)
|
data = json.load(json_file)
|
||||||
MISCALE_MAC = data["MISCALE_MAC"]
|
MISCALE_MAC = data["MISCALE_MAC"]
|
||||||
if(data["MQTT_USERNAME"] == ""):
|
MQTT_USERNAME = None if(data["MQTT_USERNAME"] == "") else data["MQTT_USERNAME"]
|
||||||
MQTT_USERNAME = None
|
MQTT_PASSWORD = None if(data["MQTT_PASSWORD"] == "") else data["MQTT_PASSWORD"]
|
||||||
else:
|
|
||||||
MQTT_USERNAME = data["MQTT_USERNAME"]
|
|
||||||
if(data["MQTT_PASSWORD"] == ""):
|
|
||||||
MQTT_PASSWORD = None
|
|
||||||
else:
|
|
||||||
MQTT_PASSWORD = data["MQTT_PASSWORD"]
|
|
||||||
MQTT_HOST = data["MQTT_HOST"]
|
MQTT_HOST = data["MQTT_HOST"]
|
||||||
MQTT_PORT = int(data["MQTT_PORT"])
|
MQTT_PORT = int(data["MQTT_PORT"])
|
||||||
MQTT_PREFIX = data["MQTT_PREFIX"]
|
MQTT_PREFIX = data["MQTT_PREFIX"]
|
||||||
TIME_INTERVAL = int(data["TIME_INTERVAL"])
|
TIME_INTERVAL = int(data["TIME_INTERVAL"])
|
||||||
|
MQTT_DISCOVERY = data["MQTT_DISCOVERY"]
|
||||||
|
MQTT_DISCOVERY_PREFIX = data["MQTT_DISCOVERY_PREFIX"]
|
||||||
HCI_DEV = data["HCI_DEV"][-1]
|
HCI_DEV = data["HCI_DEV"][-1]
|
||||||
OLD_MEASURE = ''
|
|
||||||
|
|
||||||
# User Variables...
|
# User Variables...
|
||||||
USER1_GT = int(data["USER1_GT"])
|
USER1_GT = int(data["USER1_GT"])
|
||||||
@ -74,8 +69,9 @@ except FileNotFoundError:
|
|||||||
MQTT_PORT = int(os.getenv('MQTT_PORT', 1883))
|
MQTT_PORT = int(os.getenv('MQTT_PORT', 1883))
|
||||||
MQTT_PREFIX = os.getenv('MQTT_PREFIX', 'miscale')
|
MQTT_PREFIX = os.getenv('MQTT_PREFIX', 'miscale')
|
||||||
TIME_INTERVAL = int(os.getenv('TIME_INTERVAL', 30))
|
TIME_INTERVAL = int(os.getenv('TIME_INTERVAL', 30))
|
||||||
|
MQTT_DISCOVERY = os.getenv('MQTT_DISCOVERY',True)
|
||||||
|
MQTT_DISCOVERY_PREFIX = os.getenv('MQTT_DISCOVERY_PREFIX','homeassistant')
|
||||||
HCI_DEV = os.getenv('HCI_DEV', 'hci0')[-1]
|
HCI_DEV = os.getenv('HCI_DEV', 'hci0')[-1]
|
||||||
OLD_MEASURE = ''
|
|
||||||
|
|
||||||
# User Variables...
|
# User Variables...
|
||||||
USER1_GT = int(os.getenv('USER1_GT', '70')) # If the weight is greater than this number, we'll assume that we're weighing User #1
|
USER1_GT = int(os.getenv('USER1_GT', '70')) # If the weight is greater than this number, we'll assume that we're weighing User #1
|
||||||
@ -96,6 +92,23 @@ except FileNotFoundError:
|
|||||||
USER3_DOB = os.getenv('USER3_DOB', '1988-01-01') # DOB (in yyyy-mm-dd format)
|
USER3_DOB = os.getenv('USER3_DOB', '1988-01-01') # DOB (in yyyy-mm-dd format)
|
||||||
sys.stdout.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Config Loaded...\n")
|
sys.stdout.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Config Loaded...\n")
|
||||||
|
|
||||||
|
OLD_MEASURE = ''
|
||||||
|
|
||||||
|
def discovery():
|
||||||
|
for MQTTUser in (USER1_NAME,USER2_NAME,USER3_NAME):
|
||||||
|
message = '{"name": "' + MQTTUser + ' Weight",'
|
||||||
|
message+= '"state_topic": "miScale/' + MQTTUser + '/weight","value_template": "{{ value_json.Weight }}","unit_of_measurement": "kg",'
|
||||||
|
message+= '"json_attributes_topic": "miScale/' + MQTTUser + '/weight","icon": "mdi:scale-bathroom"}'
|
||||||
|
publish.single(
|
||||||
|
MQTT_DISCOVERY_PREFIX + '/sensor/' + MQTT_PREFIX + '/' + MQTTUser + '/config',
|
||||||
|
message,
|
||||||
|
retain=False,
|
||||||
|
hostname=MQTT_HOST,
|
||||||
|
port=MQTT_PORT,
|
||||||
|
auth={'username':MQTT_USERNAME, 'password':MQTT_PASSWORD}
|
||||||
|
)
|
||||||
|
sys.stdout.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Discovery Completed...\n")
|
||||||
|
|
||||||
|
|
||||||
class ScanProcessor():
|
class ScanProcessor():
|
||||||
def GetAge(self, d1):
|
def GetAge(self, d1):
|
||||||
@ -197,6 +210,8 @@ class ScanProcessor():
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
if MQTT_DISCOVERY:
|
||||||
|
discovery()
|
||||||
BluetoothFailCounter = 0
|
BluetoothFailCounter = 0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user