Help requred as I develop Edge Driver for Secure SIR321 switch (Z-Wave)

Hi Everybody,
I am developing an edge driver for my Secure SIR321 Z-Wave switch.
I initially added the fingerprint to my clone of zwave-switch, which somewhat worked.
The SIR321 supports a temperature measurement feature which I intend to control my hot water system.
So I have written a custom edge driver which is working as well as the zwave-switch I based it on. The first problem is the temperature.
Here is my profile:

Blockquote
name: secure_sir
components:

  • id: main
    capabilities:
    • id: switch
      version: 1
    • id: refresh
      version: 1
      categories:
    • name: Switch
  • id: WaterTemperature
    capabilities:
    • id: temperatureMeasurement
      version: 1
      categories:
      • name: GenericSensor

Here is the display:

Here is the handler:

Blockquote
local function temperature_report_handler(self, device, cmd)
log.info(“temperature_report_handler”)
if (cmd.args.sensor_type == SensorMultilevel.sensor_type.TEMPERATURE)
then
local scale = ‘C’
local sensor_value = cmd.args.sensor_value
if (cmd.args.scale == SensorMultilevel.scale.temperature.FAHRENHEIT) then scale = ‘F’ end
log.info("temperature_report_handler emit_event_for_endpoint cmd.src_channel: ", cmd.src_channel, " sensor_value: ", sensor_value)
device.profile.components[“Temperature”]:emit_event({value = sensor_value, unit = scale})
– log.info(“temperature_report_handler emit_component_event”)
– device:emit_component_event(device.profile.components.WaterTemperature({value = sensor_value, unit = scale}))
– log.info(“temperature_report_handler set_field Temperature, sensor_value: >”, sensor_value, “<”)
– device:set_field(TEMPERATURE, sensor_value, {persist = true})
end
log.info(“temperature_report_handler done”)
end

Here is the logcat output:
2023-05-02T12:42:56.131932789+00:00 TRACE Secure SIR Received event with handler unnamed
2023-05-02T12:42:56.132598247+00:00 INFO Secure SIR <ZwaveDevice: ac678855-741d-4cd6-8ffd-02eba4974a67 [34] (Secure SIR321 Switch)> received Z-Wave command: {args={precision=1, scale=“CELSIUS”, sensor_type=“TEMPERATURE”, sensor_value=18.8, size=2}, cmd_class=“SENSOR_MULTILEVEL”, cmd_id=“REPORT”, dst_channels={}, encap=“NONE”, payload=“\x01\x22\x00\xBC”, src_channel=0, version=1}
2023-05-02T12:42:56.136993247+00:00 TRACE Secure SIR Found ZwaveDispatcher handler in secure_sir321
2023-05-02T12:42:56.138601747+00:00 INFO Secure SIR temperature_report_handler
2023-05-02T12:42:56.148302122+00:00 INFO Secure SIR temperature_report_handler emit_event_for_endpoint cmd.src_channel: 0 sensor_value: 18.8
2023-05-02T12:42:56.148754872+00:00 ERROR Secure SIR Secure SIR321 Switch thread encountered error: [string “st/dispatcher.lua”]:233: Error encountered while processing event for <ZwaveDevice: ac678855-741d-4cd6-8ffd-02eba4974a67 [34] (Secure SIR321 Switch)>:
arg1: {args={precision=1, scale=“CELSIUS”, sensor_type=“TEMPERATURE”, sensor_value=18.8, size=2}, cmd_class=“SENSOR_MULTILEVEL”, cmd_id=“REPORT”, dst_channels={}, encap=“NONE”, payload=“\x01\x22\x00\xBC”, src_channel=0, version=1}
[string “init.lua”]:94: attempt to index a nil value (field ‘Temperature’)

I’m a little rusty but if that’s the attempt to emit the event then it should look something like this:

evt = capabilities.temperatureMeasurement.temperature({value=sensor_value,unit=scale})
device:emit_component_event(device.profile.components['WaterTemperature'],evt)
1 Like

I have tried various ways of getting the reported temperature to display in the app but my lack of understanding of what I am doing is holding me back (What I would not give for a book on the subject).
The second problem I have is that the SIR321 supports ‘Schedule’ with 30mins, 60mins, and 120mins countdown timer based on button presses, rather than ‘on’ and ‘off’.
So, when I click the button for ‘30 minutes’ I see the following in logcat (duration_byte=30):

Blockquote
2023-05-02T19:15:12.368394678+00:00 TRACE Secure SIR Received event with handler unnamed
2023-05-02T19:15:12.369059803+00:00 INFO Secure SIR <ZwaveDevice: ac678855-741d-4cd6-8ffd-02eba4974a67 [34] (Secure SIR321 Switch)> received Z-Wave command: {args={active_id=3, aid_ro=3, aid_ro_ctl=false, cmds={{cmd_byte=“\x25\x01\xFF”, cmd_length=3}}, duration_byte=30, duration_type=0, recurrence_mode=“REPEAT_EVERY_N_HOURS”, relative=false, reports_to_follow=0, res=false, schedule_id=1, schedule_id_block=0, start_day_of_month=0, start_hour=31, start_minute=63, start_month=0, start_weekday=0, start_year=255, user_identifier=0}, cmd_class=“SCHEDULE”, cmd_id=“COMMAND_REPORT”, dst_channels={}, encap=“NONE”, payload=“\x01\x00\xFF\x30\x00\x00\x1F\x3F\x00\x1E\x00\x01\x03\x25\x01\xFF”, src_channel=0, version=3}
2023-05-02T19:15:12.370148095+00:00 DEBUG Secure SIR Secure SIR321 Switch device thread event handled

And if I cancel the timer I see the following in logcat (duration_byte=0):

Blockquote
2023-05-02T19:15:25.115809304+00:00 TRACE Secure SIR Received event with handler unnamed
2023-05-02T19:15:25.118302388+00:00 INFO Secure SIR <ZwaveDevice: ac678855-741d-4cd6-8ffd-02eba4974a67 [34] (Secure SIR321 Switch)> received Z-Wave command: {args={active_id=0, aid_ro=0, aid_ro_ctl=false, cmds={}, duration_byte=0, duration_type=0, recurrence_mode=“REPEAT_EVERY_N_HOURS”, relative=false, reports_to_follow=0, res=false, schedule_id=1, schedule_id_block=0, start_day_of_month=0, start_hour=0, start_minute=0, start_month=0, start_weekday=0, start_year=0, user_identifier=0}, cmd_class=“SCHEDULE”, cmd_id=“COMMAND_REPORT”, dst_channels={}, encap=“NONE”, payload=“\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00”, src_channel=0, version=3}
2023-05-02T19:15:25.121886971+00:00 DEBUG Secure SIR Secure SIR321 Switch device thread event handled

As I cannot find anything for ‘SCHEDULE’, my question is: is there such a thing as a fallback handler to handle ‘un handled’ events. I know, sacrilege, but I want to treat the first as ‘on’ and the second as ‘off’. Alas the SIR321 does not report the expiration of the timer, but I guess I could simulate that in my driver.

Suggestions greatly appreciated; please excuse my ignorance; I wish I understood it all better.

Works!!!

Many thanks.

1 Like

You would need to define your own handler for Schedule:CommandReport. It’s not a frequently used command class so you won’t find it in the default handlers. Below is the ST documentation on it. You should also be able to send Schedule commands to the device using Schedule:CommandSet.

https://developer.smartthings.com/docs/edge-device-drivers/zwave/generated/Schedule.html

1 Like

Thanks again @philh30 ,
The Secure SIR321 is my third edge driver but my knowledge is very basic so, such a handler would be a bit of a project.
I was a software engineer earlier in my career (Fortran, C, Java) but the only thing that I have found transferrable is debugging and determination.
I would give anything for a book on this.
And I presume the concept of an ‘everything else’ handler would go against the whole concept of Edge or Lua.

Add to your require statements at the top of init.lua (changing version if you know which version of the command class it supports):

local Schedule = (require "st.zwave.CommandClass.Schedule")({version=4,strict=true})

Add the handler. Simply assuming that duration_byte > 0 means on, while 0 means off. You’d have to play with the device to see if that’s always true.

local function schedule_command_report(driver,device,cmd)
  local event
  if cmd.args.duration_byte == 0 then
    event = capabilities.switch.switch.off()
  else
    event = capabilities.switch.switch.on()
  end
  device:emit_event_for_endpoint(cmd.src_channel, event)
end

And add the handler to the driver’s list of zwave handlers.

  zwave_handlers = {
    [cc.SCHEDULE] = {
      [Schedule.COMMAND_REPORT] = schedule_command_report,
    },
  },
1 Like

Thanks again @philh30 ,
you are 2 for 2.

I had a crack at Schedule before but with version=1 and I did not have the duration_byte logic.

Now I need to tidy up, package up, and share.

All the best,
Aidan

2 Likes

@jaidank Did you get around to sharing your Edge driver for the Secure SIR321 Z-Wave switch? If so, can you let me have a link to the channel?

Alternatively, would you be willing to share the source code for the driver?

Sorry to revive an old conversation but it’s the only reference to an Edge driver for the SIR321 I could find…

1 Like

Hi @Gary_Newell ,
yes I did. I have had it up and running for several months and actually controlling my domestic hot water (including reporting water tank temperature) for over a month now.
I will figure out channel assignments and invitations shortly and invite you.
Cheers, Aidan

1 Like

Thanks @jaidank for the quick response - that’s great news, much appreciated.
Cheers, Gary

Hi @Gary_Newell ,
Sorry about the delay, I had moved to a new MacBook and had to get the old one up and running again.
Here is the channel invitation:
─────────────────────────────────────────────────────────────────────────────
Id ee877356-6420-4f2a-a1a1-9abe48d38505
Name Secure SIR321
Profile Id 61a79569-e8fd-4a4d-9b9c-a4a55ccdd15e
Expiration
Accept URL https://bestow-regional.api.smartthings.com/invite/qWjB0dgAKD2y
─────────────────────────────────────────────────────────────────────────────

Some notes:
If you are adding a thermistor probe you will need to re-pair the SRT321 after adding the probe as it changes the device profile.
I could not get a Secure SES001 probe (I called Secure in the UK and they suggested I google for it) so I used a generic 10k NTC thermistor (a guess) which works fine.
Good luck

Hi @jaidank,
I wouldn’t call next day a delay - that’s quicker than Amazon Prime.

Driver installed & SIR321 connected and reporting temperature - thank you so much!

Cheers,
Gary

BTW I use these for temperature probes: Temperature Probe - Buy from the Genius Hub shop

1 Like

Glad it worked ok.
That probe would have been perfect for me.
I spent ages trying to source a SES001 (I knew the SES001 was NTC but not that it was 10kohm).
I will bookmark it for future use.
Some more notes:
I did not implement the ‘countdown’ feature of the SIR321.
On, off, timed off and schedule work fine in the SmartThings app.
The countdown feature works on the device but the SmartThings app finds out that the countdown has expired by polling (not a big deal for a powered device).