Comments (9)
With the same logic I noticed that the switchbot contact_sensor doesn't work properly with the original integration via bluetooth.
I created the sensors that with API 1.1, updating every 10 seconds
I don't know if this is correct but the created sensor works correctly and provides the open close status correctly.
If it helps, I attach the instructions and these too can be included in the integration
Anyone else having issues with the switchbot contact_sensor open/close states in original integration??
- resource: https://api.switch-bot.com/v1.1/devices/contact_sensor_ID/status
scan_interval: 10
headers:
Authorization: "{{ states('input_text.switchbot_token') }}"
sign: "{{ states('sensor.switchbot_sign') }}"
t: "{{ state_attr('sensor.switchbot_sign','t') }}"
Content-Type: "application/json"
nonce: ""
sensor:
- name: "SwitchBot Finestra Sala Battery"
unique_id: switchbot_finestra_sala_battery
value_template: "{{ value_json.body.battery }}"
unit_of_measurement: "°%"
device_class: battery
- name: "SwitchBot Finestra Sala brightness"
unique_id: switchbot_finestra_sala_brightness
value_template: "{{ value_json.body.brightness }}"
device_class: light
- name: "SwitchBot Finestra Sala open-close"
unique_id: switchbot_finestra_sala_oc
value_template: "{{ value_json.body.openState }}"
device_class: door
from ha-switchbot-remote.
@goodsale how did you get the auth token from the integration? i cant make this work
from ha-switchbot-remote.
@goodsale how did you get the auth token from the integration? i cant make this work
Hi, you can get the token following this https://github.com/OpenWonderLabs/SwitchBotAPI#getting-started
from ha-switchbot-remote.
@goodsale how did you get the auth token from the integration? i cant make this work
If like me you are not very experienced with code, you can look at this link.
Once you create the basis with this method to do authentication, then you can do whatever you want.
https://www.speaktothegeek.co.uk/2023/07/switchbot-api-v1-1-and-home-assistant/
from ha-switchbot-remote.
@KiraPC yeah i get it, i thought the token was exposed by the integration so i didn't have to get it outside and i could create a sensor, anyway adding Hub2 temp/humidity shouldn't be too complex their are returned by the device list in the payload
@goodsale thanks, actually i am very experienced with coding but not experienced with HA :) thats what i was looking for, i could probably just call a script instead of embedding the entire python line in the command but thanks
from ha-switchbot-remote.
@goodsale P.S. this is probably cleaner to extract the data
command_line:
- sensor:
name: switchbot_data
command: "python3 /config/packages/scripts/switchbot.py"
scan_interval: 60
json_attributes:
- temperature
- humidity
sensor:
- platform: template
sensors:
switchbot_hub2_temperature:
value_template: "{{ states.sensor.switchbot_data.attributes.temperature }}"
unit_of_measurement: "°C"
device_class: temperature
switchbot_hub2_humidity:
value_template: "{{ states.sensor.switchbot_data.attributes.humidity }}"
unit_of_measurement: "%"
device_class: humidity
Then the script is just
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
import json
import time
import hashlib
import hmac
import base64
import uuid
# Declare empty header dictionary
apiHeader = {}
# open token
token = 'TOKEN' # copy and paste from the SwitchBot app V6.14 or later
# secret key
secret = 'SECRET' # copy and paste from the SwitchBot app V6.14 or later
nonce = uuid.uuid4()
t = int(round(time.time() * 1000))
string_to_sign = '{}{}{}'.format(token, t, nonce)
string_to_sign = bytes(string_to_sign, 'utf-8')
secret = bytes(secret, 'utf-8')
sign = base64.b64encode(hmac.new(secret, msg=string_to_sign, digestmod=hashlib.sha256).digest())
#Build api header JSON
apiHeader['Authorization']=token
apiHeader['Content-Type']='application/json'
apiHeader['charset']='utf8'
apiHeader['t']=str(t)
apiHeader['sign']=str(sign, 'utf-8')
apiHeader['nonce']=str(nonce)
def get_and_dump_data(endpoint):
url = f'https://api.switch-bot.com/v1.1/{endpoint}'
response = requests.get(url, headers=apiHeader)
if response.status_code == 200:
response_json = response.json()
print(json.dumps(response_json['body'], indent=4))
return response_json['body']
else:
print('Error')
print(response.text)
return None
get_and_dump_data('devices/DEVICEID/status')
from ha-switchbot-remote.
@goodsale the purpose of this package is to support IR devices.
Have you managed to try adding Hub 2 through the Matter Server Addon? This works locally without connecting to the cloud.
from ha-switchbot-remote.
@goodsale, check the new Home Assistant update, have the native Cloud API integration option
from ha-switchbot-remote.
I encountered some issues with the native Home Assistant integration as it didn't meet my requirements effectively. The integration lacked sensor information and the capability to use custom IR commands, prompting me to explore alternatives.
I also connected the Hub via Matter, which provided temperature and humidity data, but unfortunately, light level information was not available. Matter, too, doesn't support the use of custom IR commands, limiting its compatibility to only my AC unit.
Additionally, I observed a lack of synchronization in the IR AC status. After inspecting the API, I couldn't find a method to retrieve this information.
Considering these challenges, I believe it would be beneficial to enhance the existing HACS integration. Specifically, incorporating features to fetch temperature, humidity, and light data through the API could significantly improve the integration's functionality. This would address the shortcomings I've experienced and make the integration more comprehensive.
from ha-switchbot-remote.
Related Issues (20)
- Cannot conifgure projector HOT 1
- Add topics to repository and prepare to plublic to defaults HACS repos HOT 6
- Use channel number for settop box HOT 3
- Error when executing Custom Button - "takes from 2 to 3 positional arguments but 4 were given" HOT 6
- Power status out of sync HOT 4
- Commands not working HOT 2
- No this command HOT 9
- Integration Issue When Adding Secret HOT 1
- Out of sync state with power sensor HOT 1
- Control Functions as Entites in Home Assistant HOT 10
- Deprecated constant TEMP_CELCIUS HOT 2
- ClimateEntityFeature settings issues HOT 2
- Handling status 500 from SwitchBot servers HOT 1
- Incomplete fixes for #34 and #35 HOT 2
- Warning using custom sensors (temperature for AC entity) HOT 1
- Custom/learned IR buttons not working HOT 5
- Fan on command doesn't work HOT 3
- Fan is turning on when opening info panel in HA HOT 8
- How to delete devices? HOT 2
- climate.set_temperature Causes AC to Turn off HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ha-switchbot-remote.