Comments (12)
Yes, I was also already thinking about that. will be changed (most probably this week).
from fitbit-homeassistant.
https://community.fitbit.com/t5/SDK-Development/Simulator-SSL-Problem/td-p/5002720
from fitbit-homeassistant.
@D0m3L Can you give some feedback if it works for you?
from fitbit-homeassistant.
Hey @smirko-dev thanks for the update.
Unfortunately the gallery app does not work in my HA installation. I made my own app version with fitbit-dev based on your project. In details I was not able to retrieve any other (than "[ ]") response from my HA installation after switch state change (turn_on or turn_off) which in result does not work as expected with changeEntity
function, thus I mainly get rid of return res.json();
and later function to enable status update to the watch.
I'm not a programmer, so I'm not sure what I'm writing about, or how was I able to managed this app to work. Sorry :-P
from fitbit-homeassistant.
Sorry to hear.
I'm just able to run and test via Simulator since my HA is just accessible via HTTP. So I'm actually not aware of any issues via HTTPS.
I would be interested in the changes you actually made. Maybe it helps me to improve my implementation :)
from fitbit-homeassistant.
Sure, here are the functions I remember modify:
companion/index.js
// Change entity state
function changeEntity(url, token, entity, state) {
const json = JSON.stringify({
entity_id: `${entity}`
});
let group = "switch";
if (entity.startsWith("light")) {
group = "light";
}
else if (entity.startsWith("group")) {
group = "homeassistant";
}
fetch(`${url}/api/services/${group}/${state}`, {
method: "POST",
body: json,
headers: {
"Authorization": `Bearer ${token}`,
"content-type": "application/json",
}
})
if (state === "turn_on") { state = "on"; }
if (state === "turn_off") { state = "off"; }
let msgData = {
key: "change",
id: entity,
state: state,
};
sendData(msgData);
// console.log("Change req sent to watch")
}
and to properly handle on/off events on the watch (change the state in watch app)
app/index.js
function setupList(list, data) {
list.delegate = {
getTileInfo: function(index) {
return {
type: "item-pool",
name: data[index].name,
state: data[index].state,
index: index
};
},
configureTile: function(tile, info) {
if (info.type == "item-pool") {
tile.getElementById("itemText").text = `${info.name}`;
tile.getElementById("itemState").text = `${gettext(info.state)}`;
let touch = tile.getElementById("itemTouch");
touch.onclick = evt => {
//let state = "turn_on";
if (info.state === "") { let state = "empty"; }
if (info.state === "on") { let state = "turn_off"; }
if (info.state === "off") { let state = "turn_on"; }
if (info.state === "turn_on") { let state = "turn_off"; }
if (info.state === "turn_off") { let state = "turn_on"; }
// console.log("OnClick event info.state: "+info.state+", state: "+state);
sendData({key: "change", entity: Entities[info.index].id, state: `${state}`});
};
}
}
};
list.length = data.length;
}
Thanks to this I was able to change the switch status from ON to OFF and update their status in the watch, and also was able to trigger OFF to ON action afterwords.
I think they were the only files I modified. There were plenty of tests behind, so if these are not clear, or you think I supposed to changed something else, please let me know. I'm also not a git expert, but could try to publish my complete rubbish project for your inspection.
from fitbit-homeassistant.
By the way - @smirko-dev which version of Fitbit simulator are you using? I'm facing some connectivity (SSL?) issues with "Device bridge" on v.0.9.2.
�[0m�[35;1m[2021/11/15 16:13:41:1105] NOTICE: lws_client_connect_2: 0912e530: address 027-v3-api-soa.fitbit.com
�[0m�[31;1m[2021/11/15 16:13:41:2525] ERR: SSL error: unable to get local issuer certificate (preverify_ok=0;err=20;depth=2)
from fitbit-homeassistant.
@D0m3L I checked what you changed. You removed the response of the fetch function. This fire and forget implementation doesn't care about the result from your HA instance and you update the app ui directly.
Do you see any state changes in your HA?
from fitbit-homeassistant.
Yes, that is far away from perfect, but actually it works. It changes the state in HA and also update entity state in my watch (hypothetically also in HA as I do not send GET for a current entity state) - I simply assume whenever I send POST it will trigger entity change, or rather change from ON to OFF (or othervise) from the time I run the watch app. I also assumed I know when the API is down (as I'm a good admin! and can control my internal tools), so not a big deal in my env.
It would be nice to have an automatic check, where periodically (1/s?) request for all configured entities is performed for the sake of updated state in the watch. I think this could be an overkill, but will reflect real switch state from HA (e.g. when someone actually change the state via other channel and the watch is not updated with the new state).
Anyway, instead of sending "turn_on"/"turn_off" commands you could also think of sending toggle command. An additional option of controlling entities would be nice (1. control on/off, 2. control via toggle). Pleny of ideas in my head - thanks to working simulator I expect some progress on my dev skill to achieve some of them in the code... maybe one day... ;-)
Wooh, sorry for long speach - I hope most of this is understandable.
Cheers!
Edit1:
It is worth to mention that changeEntity
function actually got an '[ ]' response whenever the HA entity state change is triggered, so not much informative in sake of integration
from fitbit-homeassistant.
On little remark, you should receive a valid JSON object and not an emtpy one (see POST https://developers.home-assistant.io/docs/api/rest/).
During my tests with the simulation it's the case. As soon as I'm able to access my HA instance remote and by HTTPS I will see if it works there as well :)
from fitbit-homeassistant.
Yup, I would expect that, but somehow on my HA setup this does not work as expected (both via HTTP nor HTTPS) - no difference if executed locally, or remote (through nginx with ssl termination):
/usr/bin/curl -ks -X POST http://localhost:8123/api/services/switch/turn_off -H "Authorization: Bearer ${haapikey}" -d '{"entity_id":"$entity_id"}'
[]
Remotely via https:
/usr/bin/curl -ks -X POST https://${sslhost}/api/services/switch/turn_off -H "Authorization: Bearer ${haapikey}" -d '{"entity_id":"$entity_id"}'
[]
The GET api/states works just fine on both plain or ssl (anonymized response):
/usr/bin/curl -ks -X GET http://localhost:8123/api/states/${entity_id} -H "Authorization: Bearer ${haapikey}"
{"entity_id": "xxxxxxxxx", "state": "off", "attributes": {"last_seen": "2021-11-16T09:20:29+01:00", "linkquality": 144, "friendly_name": "xxxxxx", "icon": "hass:ceiling-light"}, "last_changed": "2021-11-15T21:10:43.327923+00:00", "last_updated": "2021-11-16T08:20:28.842016+00:00", "context": {"id": "xxxxxxxxxxxxxxxx", "parent_id": null, "user_id": "xxxxxxxxxxxxxxx"}}
I saw that it is not only me having this: https://community.home-assistant.io/t/rest-api-empty-response/300420
I'm using latest HA core on docker.
from fitbit-homeassistant.
Thanks for sharing this info with me. I never faced such an issue.
But good to know, because of then I can consider that in my implementation :)
from fitbit-homeassistant.
Related Issues (13)
- how to privately publish/upload fba/source to fitbit studio? HOT 2
- Doesn't seem to work anymore with HA 2022.3.1 HOT 22
- add support for button entities HOT 3
- Unable to connect HOT 3
- Support for Versa 4 HOT 3
- http (no -s) or nabu casa connectivity HOT 2
- Connection Error
- Manual HOT 9
- Sort entity list HOT 1
- Not getting entities showing up. HOT 23
- Thanks! HOT 1
- allow showing temperatures HOT 1
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 fitbit-homeassistant.