luup.device_supports_service

Is the output of

for u,v in pairs(luup.devices)
 do

  if luup.device_supports_service( 'urn:upnp-org:serviceId:SwitchPower1', v.udn )
   then
    luup.log( 'Service OK: '.. v.description )
   end

 end

plausible?

Some of my motion sensors and some of my HSM100 show up …

You should replace:
if luup.device_supports_service( ‘urn:upnp-org:serviceId:SwitchPower1’, v.udn )
with:
if luup.device_supports_service( ‘urn:upnp-org:serviceId:SwitchPower1’, v.udn ) == “1”

In Lua, any value but nil is considered true, so even if luup.device_supports_service returns “0”, the expression it’s considered true.

I could be wrong, but I thought I came across this function a couple weeks ago in one of the stock Vera energy-related XML files. You may be able to check how mcv uses it - I believe they are using it to go through all devices to see if they support energy metering.

Output of

for u,v in pairs(luup.devices)
 do

  local res = luup.device_supports_service( 'urn:upnp-org:serviceId:SwitchPower1', v.udn )

  luup.log('TTT '..type(res)..' '..tostring(res))

  if res
   then
    luup.log( 'Service OK1: '.. v.description )
   end

 end

luup.log( 'Service OK End')

[tt]
50 02/07/11 14:01:07.514 luup_log:0: TTT boolean false <0x340e>
50 02/07/11 14:01:07.515 luup_log:0: TTT boolean false <0x340e>
50 02/07/11 14:01:07.517 luup_log:0: TTT boolean true <0x340e>
50 02/07/11 14:01:07.517 luup_log:0: Service OK1: B Wandspiegellampe <0x340e>
50 02/07/11 14:01:07.518 luup_log:0: TTT boolean true <0x340e>
50 02/07/11 14:01:07.519 luup_log:0: Service OK1: AZ Deckenlampe <0x340e>
50 02/07/11 14:01:07.520 luup_log:0: TTT boolean false <0x340e>
50 02/07/11 14:01:07.521 luup_log:0: TTT boolean true <0x340e>
50 02/07/11 14:01:07.522 luup_log:0: Service OK1: AZ Schreibtischlampe <0x340e>
50 02/07/11 14:01:07.523 luup_log:0: TTT boolean true <0x340e>
50 02/07/11 14:01:07.524 luup_log:0: Service OK1: K 3-in-1 Motion Sensor <0x340e>
50 02/07/11 14:01:07.525 luup_log:0: TTT boolean true <0x340e>
50 02/07/11 14:01:07.527 luup_log:0: Service OK1: K USL <0x340e>
50 02/07/11 14:01:07.528 luup_log:0: TTT boolean true <0x340e>
50 02/07/11 14:01:07.529 luup_log:0: Service OK1: K 3-in-1 Temperature Sensor <0x340e>
[…]
[/tt]

???

The 3-in-1 sensor parent device supports the SwitchPower1 service. You can see this in its description file D_GenericIO1.xml:

<service> <serviceType>urn:schemas-upnp-org:service:SwitchPower:1</serviceType> <serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId> <SCPDURL>S_SwitchPower1.xml</SCPDURL> </service>

Please note that not all my HSM100 get listed as being able to switch power.

The children of an HSM100 get mapped to

D_MotionSensor1.xml
D_LightSensor1.xml
D_TemperatureSensor1.xml

and the HSM100 itself is an [tt]urn:schemas-micasaverde-com:device:ComboDevice:1[/tt].

AFAIK, GenericIO is used for the Danfoss ‘thermostat’, not for the HSM100.

… and there is a standalone motion sensor (battery-operated) on my list (not shown in my previous posting), which - according to Vera - does support ‘urn:upnp-org:serviceId:SwitchPower1’ …

??? ???

the function just checks to see if either a command or state variable is defined for the device using that service. So if you set a variable with the switchpower service for the hsm100, then the hsm100 will be listed as supporting switchpower. Setting upnp variables is unrestricted and free form, and the engine doesn’t real know if a device actually uses it or does anything with it. So this function isn’t really definitive. In our Luup code we usually use the category instead to see what type of device it is and have hardcoded rules for lights, thermostats, etc.

IIUC, the device category gets mapped to a static(?) set of UPnP services. It shouldn’t be too difficult to use this mapping to implement a bullet-proof version of [tt]device_supports_service[/tt].