Sensor text compare text  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Hydci
Posts: 35
Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Sensor text compare text

Post by Hydci »

Hello I have a text device that and updated I would like to know if he and possible the old with the new text as in the example I found no way to do it

Code: Select all

return {

   on = { devices = { "Risque" }},
               
   execute = function(dz, item )
        if old.item.state == "RAS" and new.item.state == 'orage' then
            notification
		elseif old.item.state == "orage" and new.item.state == 'RAS' then
		    notification
        end
   end
}
User avatar
boum
Posts: 130
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Sensor text compare text  [Solved]

Post by boum »

You cannot get the previous state from the object API. You'll have to use some persistent data and store the information there.

Code: Select all

return {
   on = { devices = { "Risque" }},
   data = {
      previousRisque = { initial = "RAS" }
   },
   execute = function(dz, item)
      local state = item.state
      local previous = dz.data.previousRisque
      dz.data.previousRisque = state  -- don't forget to update the persistent data!
      if previous == "RAS" and state == 'orage' then
          notification()
      elseif previous == "orage" and state == 'RAS' then
	  notification()
      end    
   end
}
Documentation is there: https://www.domoticz.com/wiki/DzVents:_ ... stent_data
Hydci
Posts: 35
Joined: Tuesday 04 June 2019 21:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Sensor text compare text

Post by Hydci »

Hello, thank you for your answer actually I have everything but thank you so thank you for the solution and for the redirection to the link of the wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest