Pleg newbie some help please with first Pleg!

Hello

I have never used PLEG before and always just used code snippets off the forum. I have a new Vera Edge I am transferring too and would like to now use and learn PLEG. I have installed the Program Logic Core and the Program Logic Event Generator plug-ins.

I am wanting to create my first pleg that is based on an existing scene on my old VeraLite. The scene checks to see if a virtual switch is turned on, if it is then it gets the status of the curtains to see if they are already open? If they are, it runs a scene to close the curtains. The trigger for the scene is my Kodi PC starting to play a Movie.

Link_KODI_to_devices = luup.variable_get(“urn:dcineco-com:serviceId:MSwitch1”,“Status1”,44) – Is the MultiSwitch Switch 1 = ON
if(Link_KODI_to_devices==“0”)then return false end – If its OFF end and do nothing
are_curtains_open = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”,“LoadLevelStatus”,70) – If its ON get status of curtains
if(are_curtains_open==“100”)then – If the curtains are OPEN then run a scene to close the curtains
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”,“RunScene”,{SceneNum=“31”},0)
end

Scene Trigger = Player State Changes → Video Starting

and also in the trigger of this old scene I also had some additional LUUP code to check it is night time

if ( luup.is_night() ) then
return true
else
return false
end

I would like to do all this in a PLEG, here is what I have setup but its not working as expected:

PLEG-1.png

Trigger = Kodi PC starts playing Video

PLEG-2.png

Device Properties

  1. Curtains_Status ?
    0 = Closed / 100 = Open
  2. Is_Night ?
    Day and Night plug-in 0 = Night / 1 = Day
  3. Kodi_Linked ?
    MultiSwitch Status1 - 0 = Off (Not Linked) / 1 = On (Linked)

PLEG-3.png

Conditions

Its Night time and Kodi is Linked (Switch1 = ON) and Curtains are already open

Is_Night==0 and Kodi_Linked==1 and Curtains_Status==100

PLEG-4.png

Actions

Device = Lounge Curtains
Device Action = Down (I couldn’t see Close or Open in the actions list so used down which closes the curtains).

Here is what happens, the curtains are open, it is night here now and the Kodi PC is not playing anything and its status is Video_Stop and the MultiSwitch Switch1 is OFF.

If I then turn on MultiSwitch Switch1 to ON (meaning this links Kodi to Vera) the curtains then close right away.

They should not close when I turn on or off Switch1. They should only close when Kodi starts playing a Video.

Also whilst the PLEG is armed and the MultiSwitch Switch1 is ON, I cannot just operate the curtains device in the Vera GUI normally and press the Open button, the curtains don’t open, they do close however using the close button.

I have to either bypass the PLEG or turn off the Switch1 and then the Open command on the curtain device works as it should.

I guess it can only be my Conditions which are wrong.

Any ideas?

Thanks

I strongly recommend the ‘PLEG Basics’ document, which should solve your problems. A forum search should locate it easily.

Part is using PLEG is also to use the “Status” report … Post your Status report as a PDF.
There is a lot more info and makes it easier to analyze than the Screen Snapshots.

Hi Richard

Thank you, here is the report

You want to look at the Sequence Operator to limit the action until the Kodi transitions AFTER the multi switch is in the correct state.

Also I would use TRIGGERS where appropriate as opposed to Device Parameters. (i.e. NIGHT, and Kodi_Linked) … otherwise you will need intermediate expressions for the sequence operator.

Hi

I have it working now mainly, the main issue was I was not adding the triggers in to the conditions.

But perhaps its not the best way to set it all up as you suggested. But here is what I have at the moment.

Basically this is what happens:

  1. If its night and MultiSwitch Switch1 is ON and the curtains are open (>90) and I start to play a video in Kodi the curtains close and the lights dim to 25%

  2. If the video is paused or stopped or ends the lights brighten up to 100% (has to be night and MultiSwitch Switch1 has to be on)

  3. If the video is resumed (say I paused the video and then pressed play again) the lights dim back down to 25%

  4. If its not night none of this should happen

  5. If the MultiSwitch Switch1 is not ON none of this should happen.

PLEG Triggers.png

Triggers are the Kodi PC Player State changing:

VideoEnded
VideoPaused
VideoResume
VideoStarting
VideoStopped

Device Properties.png (Same as before)

Device Properties

  1. Curtains_Status ?
    0 = Closed / 100 = Open
  2. Is_Night ?
    Day and Night plug-in 0 = Night / 1 = Day
  3. Kodi_Linked ?
    MultiSwitch Status1 - 0 = Off (Not Linked) / 1 = On (Linked)

PLEG Conditions.png

kodivideostart - Is_Night==0 and Kodi_Linked==1 and Curtains_Status>90 and VideoStarting==1

kodivideostop - Is_Night==0 and Kodi_Linked==1 and (VideoStopped==1 or VideoPaused==1 or VideoEnded==1)

kodivideoresume - Is_Night==0 and Kodi_Linked==1 and Curtains_Status<10 and VideoResume==1

PLEG Actions.png

kodivideoresume = If the video is resumed the lights dim to 25%
kodivideostart = If its night and MultiSwitch Switch1 is ON and curtains are <90 it closes the curtains and dims the lights to 25%
kodivideostop = If the video is paused or stopped or ends the lights brighten to 100%

The thing that is not working / correct is when I start to play a second movie / video the lights do not auto dim to 25% because the condition is checking that the curtain is >90 and at this point the curtains have closed already e.g. 0. So I haven’t got the conditions quite right yet.

OK I added a fourth condition for if the curtains are already closed to dim the lights to 25% on Kodi video start and its all working properly now.

Condition name: videostartcurtainsclosed
Condition: Is_Night==0 and Kodi_Linked==1 and Curtains_Status<10 and VideoStarting==1

I quite like PLEG, I think once you get your head round how to construct the conditions it will be a very powerful tool, rather than me doing it the old way and using LUUP code snippets found around the forums.

Cheers

PLEASE QUIT POSTING SCREEN SHOTS …

Post a status report (in PDF Format, there are plenty of free PDF printers) … we can see everything and a lot more in a single report.