Need a little help transforming DSL Rules to the new JSScript

I hope you don’t mind me writing your rule in JRuby

Things to note:

  • This is a fully file based rule, not GUI, so it includes the trigger and rule definition, not just the rule ‘body’
  • Don’t need to download the image as a file, then later on delete them (unless you want to keep the images?). Pushover lets you send the raw image (in memory)
  • Not using sleep. Instead we use a timer for fetching the snapshot from each camera, so the fetching runs in parallel
  • I haven’t tested this, so there may be some minor errors. I’d be happy to help further.
require 'openhab'
require 'net/http'

CAMERAS = { 
  id1: 'Ostseite',
  id2: 'Haupteingang',
  id3: 'Westseite',
  id4: 'Terrasse',
  id5: 'Garage'
}

rule 'Internal Alarm' do
  changed V_Alarm_Internal, to: ON
  triggered do |item|  
    pushover.sendPriorityMessage("#{item.id} wurde geöffnet", "ACHTUNG, (STILLER) ALARM!!!", 1)
  end
end

rule 'External Alarm' do
  changed V_Alarm_External, to: ON
  triggered do |item|
    pushover.sendPriorityMessage("#{item.id} wurde geöffnet", "ACHTUNG, ALARM!!!", 2)

    CAMERAS.each do |id, name|
      after(3.seconds) do
        source = "http://xxxxxxxxxx:8080/xxxxxx/jpeg/xxxxxxxx/#{id}/s.jpg"
        image = Net::HTTP.get(URI(source))
        pushover.sendAttachmentMessage(name, name, image, nil)
      end
    end
  end
end

def pushover 
  things['pushover:pushover-account:xxxxxxxxx']
end