Read the statement by Michael Teeuw here.
Getting LED Strip on in conjunction with MMM-Pir
-
@sdetweil , as expected :-( I’m not able to figure this out…
I’m in the fog of instances and .this / not .this…
Can somebody guid me, please?
I’m trying to configure MMM-NotificationTrigger to send two different notifications depending on the payload.
So my idea is to evaluate payload in given payload filter, store the result in a variable and decide with this variable which fire statement is the correct one.
But I’m stuck in referencing this variable which seems to be unknown outside the trigger-evaluation part.This currently is my (non working) approach in my config.js file:
{ module: 'MMM-NotificationTrigger', disabled: false, config: { useWebhook: false, // If you want to activate webhook as Notification emitter, set true. (eg. IFTTT) triggers:[ // Array of triggers. { trigger: "MMM_PIR-SCREEN_POWERSTATUS", //REQUIRED triggerPayloadFilter: (payload) => { //OPTIONAL should return true or false if (payload.value == 'true' ) { this.ScreenStatus = "on" return true } this.ScreenStatus = "off" return true }, fires: [ // Array of fires. You can enable multi-firing with one trigger. { if (ScreenStatus == 'on') { fire: "SCREEN_IS_ON", } else { fire: "SCREEN_IS_OFF", } }, ], }, ] }, },
I’ve tried to reference Screenstatus with “payload.ScreenStatus” as well as “triggerPayloadFilter.screenstatus”, but the dot is rejected as config error in both cases.
Any tip is highly appreciated.
Sorry for being this stupid…Warm regards,
Ralf -
@rkorell i haven’t tried this but it should work
anything created IN the filter will die in the filter
so you need something persistent
lets cheatas the config is persistent lets add your variable to the config block, the module wont know its there and wont use it
config: { useWebhook: false, // If you want to activate webhook as Notification emitter, set true. (eg. IFTTT) ScreenStatus:null, triggers:[
now in your trigger filter and fires use
this.config.ScreenStatususing the browser developers window , sources tab expand left nav to find the modulename.js) you should find the module source where it calls the filter and put a stop there and(f5 to reload the page) step INTO ( down arrow icon above the code in sources view) to see your filter execute
-
@sdetweil , thanks!!!
Sounds plausible but doesn’t work :-(
I can reference this.config.ScreenStatus in the TriggerPayloadFilter.
But when I do this, the fire isn’t working (no notification broadcast appears).
In addition referencing of this.config.ScreenStatus in the fire block causes an error “Cannot read properties of undefined (reading ‘ScreenStatus’)”…
Any direct reference in the fire block in an IF statement creates an "unecpected ‘this’ " error message …you can see my dumb trials commented in this snippet:
{ module: 'MMM-NotificationTrigger', disabled: false, config: { ScreenStatus:"INIT", useWebhook: false, // If you want to activate webhook as Notification emitter, set true. (eg. IFTTT) triggers:[ // Array of triggers. { trigger: "MMM_PIR-SCREEN_POWERSTATUS", //REQUIRED triggerPayloadFilter: (payload) => { //OPTIONAL should return true or false if (payload.value == 'true' ) { //this.config.ScreenStatus = "on" return true } //this.config.ScreenStatus = "off" return true }, fires: [ // Array of fires. You can enable multi-firing with one trigger. { /* if (this.config.ScreenStatus == 'on') { fire: "SCREEN_IS_ON", } else { fire: "SCREEN_IS_OFF", }*/ //fire: this.config.ScreenStatus, fire: "BROADCAST", }, ], }, ] }, },
I’m SO sorry…
Ralf -
@rkorell yeh, sorry, didn’t give this enough viewing/thinking time…
the fires section doesn’t support code, its all literals.
I don’t know if you can attach a function (which returns the literal) to itfires: ()=>{ if (this.config.ScreenStatus == 'on') return "BROADCAST"; else return "?????"
-
@sdetweil Yes, sounds like a brillant idea.
But if I assign a value to this.config.ScreenStatus within the trigerPayloadFilter section the fire section isn’t working - so your thought is great but I cannot try this …Any idea why the fire section is skipped?
THANKS for your effort!!
Ralf -
@rkorell well, skipped…
because the code it looking for a literal, and the function is not…
the NotificationsTrigger module will have to be changed -
@sdetweil O.K.,
if I have to change modules, I can do this at the “root” - which is the MMM-Pir …
I will at least have a closer look to the MMM-Notification module - maybe a good starting point to develop a completely new (forked) module…Thanks for your engagement anyway!
Warm regards,
Ralf -
@rkorell ok, its a tiny change to Trigger module…
-
@sdetweil from your perspective :-)
Just had a deeper look into code and I didn’t understand that much…