When you connect to the websocket you will het any information on every single device known in Pimatic - including states, values and unit. During the connection you will be updated on the changes that happen.
When you get a update you only get the value, not the unit.
Is this by intend? Any chance this could be added ?
-
unit is not send to the websocket-API on change?
Like my projects and help? Consider donating electroneum etnjwAKGPqF6omQWRmpp9u2BPyVDG9VuyRQjNJ1S8yfBdfR9qeUQ46kRy8KS2CNqbpNLRrsgmNW6F2TMzxmZgPrh6KctrkrYbm
-
@koffienl said in unit is not send to the websocket-API on change?:
Is this by intend?
Yes, this is by design. The assumption is that the unit is part of the static schema information. The device schema information is initially populated for all devices and variables with the “devices” and “variables” events. The schema call also be queried for an individual device using the getDeviceConfigSchema. Moreover, there are events which indicate when an device or variable has been added or removed.
Any chance this could be added ?
No, unless there is a good reason to do so
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law
-
Hi @koffienl and @mwittig Now I create a script that sent the data to Influxdb. Units I read in advance from
variables
.socket.on('variables', function(variables) { for (variable in variables) { console.log(variable.name); console.log(variable.unit); //set unit for measurement in InfluxDB } });
And then I get values.
socket.on('deviceAttributeChanged', function(attrEvent) { console.log(attrEvent.deviceId + "." + attrEvent.attributeName); console.log(attrEvent.value); //set value for measurement in InfluxDB });
@mwittig Is this the right way?
Pimatic = Smart Home
-
@mwittig said in unit is not send to the websocket-API on change?:
@koffienl said in unit is not send to the websocket-API on change?:
Is this by intend?
Yes, this is by design. The assumption is that the unit is part of the static schema information. The device schema information is initially populated for all devices and variables with the “devices” and “variables” events. The schema call also be queried for an individual device using the getDeviceConfigSchema. Moreover, there are events which indicate when an device or variable has been added or removed.
Any chance this could be added ?
No, unless there is a good reason to do so
Makes sense
I have solved it now on my side since you are correct : you get all the info on connect including the unit. Overtime the value will change but not the unit.Like my projects and help? Consider donating electroneum etnjwAKGPqF6omQWRmpp9u2BPyVDG9VuyRQjNJ1S8yfBdfR9qeUQ46kRy8KS2CNqbpNLRrsgmNW6F2TMzxmZgPrh6KctrkrYbm
-
@wutu said in unit is not send to the websocket-API on change?:
Hi @koffienl and @mwittig Now I create a script that sent the data to Influxdb. Units I read in advance from
variables
.socket.on('variables', function(variables) { for (variable in variables) { console.log(variable.name); console.log(variable.unit); //set unit for measurement in InfluxDB } });
And then I get values.
socket.on('deviceAttributeChanged', function(attrEvent) { console.log(attrEvent.deviceId + "." + attrEvent.attributeName); console.log(attrEvent.value); //set value for measurement in InfluxDB });
@mwittig Is this the right way?
You should also do a check if the device has a unit in the first place.
Like my projects and help? Consider donating electroneum etnjwAKGPqF6omQWRmpp9u2BPyVDG9VuyRQjNJ1S8yfBdfR9qeUQ46kRy8KS2CNqbpNLRrsgmNW6F2TMzxmZgPrh6KctrkrYbm
-
@koffienl said in unit is not send to the websocket-API on change?:
You should also do a check if the device has a unit in the first place.
Infludb does not matter if I set the empty unit and not all of my variables have it.
I have a problem with determining if the value is float-transferable. Unfortunately, it is not possible to find out in advance from the variables.
And you need to test it for each deviceAttributeChanged. Can this be solved in a different way?Pimatic = Smart Home
-
@wutu said in unit is not send to the websocket-API on change?:
@koffienl said in unit is not send to the websocket-API on change?:
You should also do a check if the device has a unit in the first place.
Infludb does not matter if I set the empty unit and not all of my variables have it.
I have a problem with determining if the value is float-transferable. Unfortunately, it is not possible to find out in advance from the variables.
And you need to test it for each deviceAttributeChanged. Can this be solved in a different way?Correct me if I’m wrong, but if you simply would insert the variable
variable.unit
into a database, you would insert the string ‘undefined’ when there is no unit defined?Like my projects and help? Consider donating electroneum etnjwAKGPqF6omQWRmpp9u2BPyVDG9VuyRQjNJ1S8yfBdfR9qeUQ46kRy8KS2CNqbpNLRrsgmNW6F2TMzxmZgPrh6KctrkrYbm