I wish to change the code to log motion activity as a boolean instead of a string. The reason being is that the database I use for all device data already has lots of motion activity and I really don't want to make a parallel database.
Here is an example of what is in my database now
> select * from motion where time > now()-1h
name: motion
time deviceId deviceName groupId groupName hubId hubName locationId locationName type unit value
---- -------- ---------- ------- --------- ----- ------- ---------- ------------ ---- ---- -----
2022-09-21T23:48:32.862585057Z Driveway Motion bool false
HE logs show this error
postToInfluxDB(): Something went wrong! Response from InfluxDB: Status: 400, Headers: [X-Influxdb-Error:partial write: field type conflict: input field "value" on measurement "motion" is type string, already exists as type boolean
I'm almost certain this is all that needs to be changed but I'm not a groovy/HE programmer. This is the InfluxDB Logger app code at line 450
else if ('motion' == evt.name) { // Motion: Calculate a binary value (active = 1, inactive = 0)
unit = 'motion'
value = '"' + value + '"'
valueBinary = ('active' == evt.value) ? '1i' : '0i'
data += ",unit=${unit} value=${value},valueBinary=${valueBinary}"
}
Bonus points if you can also tell me how to change the instance name so I can easily see which is which like we can with Maker API
More of a workaround than a solution.... Could you maintain a virtual switch in HE in line with the motion sensor, e.g. when motion is detected the switch is on, else off? Not ideal... I'm sure someone will be able to assist with the code....
Yep. But I don't see how the driver matters because it's only the write to InfluxDB that's having an issue. Maybe I wasn't clear but I think all that needs to be done is to change the type of the motion attribute from string to bool in the write.
I am expecting the logger is setup to subscribe / listen for events on devices you select. Potentially in this case the device is recording (or not recording) a different unit for motion, hence the error about a string verses a boolean.
What do you see if you open the Events screen for the device? Where there are events for motion, what are the units. That said, I see my motion sensors do not record a unit... Anyway, would be interesting to see what is recorded.
I have no familiarity with InfluxDB or whatever API or other mechanism of access this app might be using, so this may not work.
Some apps offer this; if not, you can add a line like this to the UI, maybe before the first input() (it's pretty similar in that it needs to reside in a section):
You could try that too; again, I don't know how how either InfluxDB or the app you're using works. The other consideration would be what type, if any, was specified for valueBinary, which is not apparent from the snippet.
binary would indicate it is expecting just that, a binary value, but like you said, it is not clear... I still feel like the issue is more likely fiurther back in the device driver, given others must be using the logger successfully.
My gut-feel would be to setup a virtual sensor and test that with the logger. If that works then I would look at what is different about the logging of events for the device you are interested in compared to the test virtual motion sensor, looking at the Events page for both when recording motion activation, in particular the Unit.