We have moved at community.getvera.com

Author Topic: [SOLVED] Category Variable Set - Possible to set all devices at once?  (Read 2618 times)

Offline konradwalsh

  • Hero Member
  • *****
  • Posts: 566
  • Karma: +19/-6
Hi

I have been playing with this

Code: [Select]
luup.inet.wget("http://192.168.2.4:3480/data_request?id=action&output_format=xml&Category=4&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&action=Tripped&setTargetValue=0")
using setTargetValue

and

Code: [Select]
luup.inet.wget("http://192.168.2.4:3480/data_request?id=action&output_format=xml&Category=4&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&action=Tripped&newTargetValue=0")
using newTargetValue

My goal is the sweep through all Motion sensors and reset them to Tripped=0

cant seem to get that right though



reference -
Code: [Select]
http://wiki.micasaverde.com/index.php/Luup_Requests
« Last Edit: June 10, 2015, 07:18:53 am by konradwalsh »

andreimios

  • Guest
Hi konradwalsh,

Take a look here:

Quote
http://wiki.micasaverde.com/index.php/Luup_UPnP_Variables_and_Actions#SecuritySensor1
There is no "Tripped" action for a security sensor, so it will not work. It seems that you want to do this with Luup code, so there is no need to use the HTTP requests, there are dedicated functions in Lua for this too :
Quote
http://wiki.micasaverde.com/index.php/Luup_Lua_extensions

You can use the following code and change it based on your needs :

Quote
for dev, attr in pairs(luup.devices) do
   if attr.category_num == "4" and attr.subcategory_num == "3" then
      luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", "0", dev)
   end
end

Let me know if you have any other questions

Best Regards,

- Andrei -

Offline konradwalsh

  • Hero Member
  • *****
  • Posts: 566
  • Karma: +19/-6
Hi Andrei

Thanks!!.. yes.. I am using it in  luup.. I did the http call cause sometimes its easier to debug...

You method works without the if the statement
which means I can run it, and reset each security sensor from tripped 1 to 0

but with the if statement the line never runs...

Code: [Select]
for k, v in pairs(luup.devices) do
  luup.task(k,1,"I got here", 1)
 if v.category_num == "4" and v.subcategory_num == "3" then
             luup.task("Yes",1,"I got here", 2)
 
        luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", "0", k)

     end
end

can you see any reason why?

Offline konradwalsh

  • Hero Member
  • *****
  • Posts: 566
  • Karma: +19/-6
Code: [Select]
if v.category_num == "4" and v.subcategory_num == "3" then

problem solved... I removed "" around the numbers

Code: [Select]
if v.category_num == 4 and v.subcategory_num == 3 then

Thanks for your help

andreimios

  • Guest
Hi konradwalsh,

Your welcome and sorry for the "" issue.  I'm glad I could help.

Best Regards,

- Andrei -

Offline hmspain

  • Hero Member
  • *****
  • Posts: 528
  • Karma: +16/-8
A little help please?  The following code does not appear to "untrip" my sensors.  Does anyone see the problem?

-- (motion sensors)

for k, v in pairs(luup.devices) do
  luup.task(k,1,"I got here", 1)
 if v.category_num == "4" and v.subcategory_num == "3" then
             luup.task("Yes",1,"I got here", 2)
 
        luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", "0", k)

     end
end

-- (door sensors)

for k, v in pairs(luup.devices) do
  luup.task(k,1,"I got here", 1)
 if v.category_num == "11" and v.subcategory_num == "0" then
             luup.task("Yes",1,"I got here", 2)
 
        luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", "0", k)

     end
end
VeraPlus, Nest Cameras (6), Siren, Hue Bulbs/Strips/Blooms (65), Fan Dimmer (6), Aeon 4-in-1s (10), Water Sensors (3), Z-Wave Switches (20), Nest Smoke/CO Protects (5), Ecobee 3, HEM Gen2s (2)

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Quote
A little help please?  The following code does not appear to "untrip" my sensors.  Does anyone see the problem?

It may be that your calls to luup.task(...) are blowing-up and aborting the code. See here for the correct way to use the handle (fourth argument).

You might find LuaTest helpful for debugging code like this. It gives fairly clear error messages and also allows the use of print(...) statements to show progress.


Offline hmspain

  • Hero Member
  • *****
  • Posts: 528
  • Karma: +16/-8
Quote
A little help please?  The following code does not appear to "untrip" my sensors.  Does anyone see the problem?

It may be that your calls to luup.task(...) are blowing-up and aborting the code. See here for the correct way to use the handle (fourth argument).

You might find LuaTest helpful for debugging code like this. It gives fairly clear error messages and also allows the use of print(...) statements to show progress.

I'm not a programmer, sorry!  When I hear "removing the quotes was the problem", I think either you need to remove the quotes to solve the problem, or removing the quotes WAS the problem :-).

I duplicated the code for the door sensor devices (I just changed the category and subcategory).

I liked the old script days when I could step code through line by line.  If anyone can discern specifically what is wrong with my code, please let me know.  Others seem to have this running.
VeraPlus, Nest Cameras (6), Siren, Hue Bulbs/Strips/Blooms (65), Fan Dimmer (6), Aeon 4-in-1s (10), Water Sensors (3), Z-Wave Switches (20), Nest Smoke/CO Protects (5), Ecobee 3, HEM Gen2s (2)

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Quote
If anyone can discern specifically what is wrong with my code, please let me know.

Try this:

Code: [Select]
-- (motion sensors)
for k, v in pairs(luup.devices) do
   if v.category_num == 4 and v.subcategory_num == 3 then
      luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", "0", k)
   end
end

Code: [Select]
-- (door sensors)
for k, v in pairs(luup.devices) do
   if v.category_num == 11 and v.subcategory_num == 0 then
      luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", "0", k)
   end
end

Offline hmspain

  • Hero Member
  • *****
  • Posts: 528
  • Karma: +16/-8
Quote
If anyone can discern specifically what is wrong with my code, please let me know.

Try this:

Code: [Select]
-- (motion sensors)
for k, v in pairs(luup.devices) do
   if v.category_num == 4 and v.subcategory_num == 3 then
      luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", "0", k)
   end
end

Code: [Select]
-- (door sensors)
for k, v in pairs(luup.devices) do
   if v.category_num == 11 and v.subcategory_num == 0 then
      luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", "0", k)
   end
end

Thank you RexBeckett, works perfectly!  I manually set a couple motion sensors to "Tripped" = 1 and then ran the code.  Everything is untripped now :-).
VeraPlus, Nest Cameras (6), Siren, Hue Bulbs/Strips/Blooms (65), Fan Dimmer (6), Aeon 4-in-1s (10), Water Sensors (3), Z-Wave Switches (20), Nest Smoke/CO Protects (5), Ecobee 3, HEM Gen2s (2)