Page 1 of 1

Sensor text compare text

Posted: Tuesday 12 November 2019 13:02
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
}

Re: Sensor text compare text  [Solved]

Posted: Tuesday 12 November 2019 15:44
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

Re: Sensor text compare text

Posted: Tuesday 12 November 2019 15:51
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