[Edge drivers] Issue with default values in profile's preferences

Some have changed without warning, as almost always, that takes time to set the default value of the preferences and found a null instead of 0.

Before, driver set the defaults preferentes when starting the driver.

Hi @nayelyz
The defaults of the preferences were previously established when starting the driver with the set profile, or at least I had never seen that after 8 minutes of running the driver the preference was still at a null value instead of the default

driver installation start time:
2023-02-05T03:31:39.345179482+00:00 TRACE Fibaro Smart Implant BETA Z-Wave Device: 90395e70-07a9-4915-a570-941b5930c937
Manufacturer: 0x010F Product Type: 0x0502 Product ID: 0x2000

Time of error preference null value:

2023-02-05T03:39:16.368738009+00:00 ERROR Fibaro Smart Implant BETA Fibaro Smart Implant thread encountered error: [string “st/dispatcher.lua”]:233: Error encountered while processing event for <ZwaveDevice: 90395e70-07a9-4915-a570-941b5930c937 [42] (Fibaro Smart Implant)>: arg1: {args={precision=1, scale=“CELSIUS”, sensor_type=“TEMPERATURE”, sensor_value=32.7, size=2}, cmd_class=“SENSOR_MULTILEVEL”, cmd_id=“REPORT”, dst_channels={0}, encap=“NONE”, payload=“\x01\x22\x01\x47”, src_channel=7, version=1}
> [string “init.lua”]:124: attempt to perform arithmetic on a nil value (field ‘internalTempOffset’)

The only problem may be in some driver that the error causes stop the function where the error occurs and some of the configuration is skipped.

In any case, I will put a condition so that it is not executed if the value is null

You can use value 0 without any problem

Hi, @Mariano_Colmenarejo
Can you put me up to speed on this issue, please?

Do you mean that despite using the property “default” in the profile set as 0, it is being ignored?

Hi @nayelyz

What I have told in the post above.

It seems that the defaults defined in the profile preferences are not set when the device is installed.

When the driver goes to perform some operation with the values of the preferences, it encounters null values and an error is produced that stops the function.

This didn’t happen before it happened before

Hi @Mariano_Colmenarejo , I’m Alejandro Padilla from the dev support team.

We tried to reproduce your issue, but unfortunately, we can’t. For this reason, we need your help by sharing with us the profile definition you are currently using to generate the problem, please.

Hi @AlejandroPadilla

I did not detect it and I have not been able to replicate it either.
It was reported by a user @sflamm when he installed a fibaro smat implant and when calculating the corrected temperature with a preference, he found a null value instead of the default value, until he manually set to value = 0 in preferences.

ame: fibaro-smart-implant-temp
components:
- id: main
  label: Internal Temperature
  capabilities:
    - id: temperatureMeasurement
      version: 1
    - id: refresh
      version: 1
  categories:
  - name: Thermostat
- id: externalTemp1
  label: External Temperature
  capabilities:
    - id: temperatureMeasurement
      version: 1
    - id: refresh
      version: 1
  categories:
  - name: Thermostat
- id: out1
  label: Out-1
  capabilities:
    - id: switch
      version: 1
    - id: refresh
      version: 1
  categories:
  - name: Switch
- id: out2
  label: Out-2
  capabilities:
    - id: switch
      version: 1
    - id: refresh
      version: 1
  categories:
  - name: Switch
preferences:
  - name: "internalTempOffset"
    title: "Internal Temperature Custom Offset"
    description: "Select Internal Temperature Custom Offset (-20.0º to +20.0º)"
    required: false
    preferenceType: number
    definition:
      minimum: -20
      maximum: 20
      default: 0
  - name: "externalTempOffset1"
    title: "External Temperature Custom Offset"
    description: "Select External Temperature Custom Offset (-20.0º to +20.0º)"
    required: false
    preferenceType: number
    definition:
      minimum: -20
      maximum: 20
      default: 0 

The error was in this line:
> [string “init.lua”]:124: attempt to perform arithmetic on a nil value (field ‘internalTempOffset’)

local function temperature_report_handler(self, device, cmd)
print(“<< Temperature_report_handler >>”)

   if (cmd.args.sensor_type == SensorMultilevel.sensor_type.TEMPERATURE) then
     local custom_temp = cmd.args.sensor_value
     if cmd.src_channel == 7 then -- Internal temperature
      ***line 124*** custom_temp = custom_temp + device.preferences.internalTempOffset *****
     elseif cmd.src_channel == 8  then -- Externaltemperature 1
       custom_temp = custom_temp + device.preferences.externalTempOffset1
     end
     localscale = 'C'
     if (cmd.args.scale == SensorMultilevel.scale.temperature.FAHRENHEIT) then scale = 'F' end
     device:emit_event_for_endpoint(cmd.src_channel, capabilities.temperatureMeasurement.temperature({value = custom_temp, unit = scale}))
   end

I don’t know if this error was something momentary and it has been self fixed, I couldn’t reproduce it in other profiles since I don’t have that device.

I don’t know if @sflamm it has happened this error again

Hi @sflamm, I’m Alejandro Padilla from the dev support team

Can you confirm if this error has happened again?

Hi,

The problem had occurred in one of the first driver versions - got the divide by zero error when the parameter’s default value was zero. I fixed it by choosing the smallest non zero value to use.

In the later versions of the driver I have not encountered the problem. I currently have the values set to zero as default and it is working without error


Another error I received was that for Automation rules it was still showing parameter ranges as Celsius even though my locale sets the temperature in Fahrenheit. Over time that seemed to automatically correct itself without my making any adjustments on my side. But when the rule was originally created it was unusable - later when I returned to it the range has “magically” changed to Fahrenheit

Sorry to correct you @sflamm, the error was because the driver was trying to add a received temperature value from device with a null preference value, when the preference value should be 0.

You will no longer see this error if you do not delete the device from the App, then all the values of the device will be deleted and when you pair device again it should return to the default value 0 or fail if the driver does not receive the default value default = 0 and find a null value

@sflamm if you have the chance to reproduce the issue so we can open an investigation about it, please share the following with us after doing so:

  1. logs of the driver
  • Open the ST CLI
  • Enter the command smartthings edge:drivers:logcat IdDriver
  • Enter the hub IP
  • Now you must be available to see the logs
  1. logs of your hub
  • In the IDE enter “my hubs”
  • Enter the corresponding Hub and go to “view utilities”
  • Click on “send” below "send hub logs

If not, we will be attentive of other reports about the same issue.

I had recorded the logs at the time here:

I will need to setup a new implant if you want me to reproduce for current driver (the other device is now in use)

Hi @sflamm

Thanks for the comment, but unfortunately we need more recent driver and Hub logs to generate a report to the corresponding team, the most recent logs saved in the Hub can help us investigate.

If you have the chance to reproduce the issue an share with us the recent logs, it would help a lot. If not, we will be attentive of other reports about the same issue.