<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Module help for variable]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I’ve created a small module to turn my monitor off when my nest realizes I’ve left the house.  This uses a notification from mmm-nest-status.  Since I’m a noob I don’t understand how to keep track of a variable between notifications.  I’m guessing I need something in start: ?  Here is the code:</p>
<pre><code>Module.register("controlMonitor", {
	defaults: {},
	notificationReceived: function(notification, payload, sender) {
		if (notification === 'MMM_NEST_STATUS_UPDATE') {
            this.processData(payload);
		}
	},
	processData: function(data) {
		var awayState = 'unknown'; // 'home', 'away'
		// check for away state
		if (data.devices &amp;&amp; data.structures) {
			var sId = Object.keys(data.structures)[0];
			var sObj = data.structures[sId];
			awayState = sObj.away;
		}
		var oldAwayState = this.awayState;
		this.awayState = awayState;
		// if state has changed and new is away then shut monitor off
		if (!(this.oldAwayState === awayState) &amp;&amp; (this.awayState === 'away')) {
			//this.sendNotification("REMOTE_ACTION", {action: 'MONITOROFF'});
				console.log(this.name + "awayState " + awayState + "oldAwayState " + oldAwayState + " " + this.datetime4log());
		}
		// if state has changed and new is home then turn monitor on
		if (!(this.oldAwayState === awayState) &amp;&amp; (this.awayState === 'home')) {
			//this.sendNotification("REMOTE_ACTION", {action: 'MONITORON'});
				console.log(this.name + "awayState " + awayState + "oldAwayState " + oldAwayState + " " + this.datetime4log());
		}
	},
	datetime4log: function() {
		var d = new Date();
		return (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
		}
});

</code></pre>
<p dir="auto">What’s happing now is the home state is firing off every 2 minutes for every notification.  I  need a module level oldAwayState variable, so the when I get the update I can test against it to only fire off an update if there is a change.</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.magicmirror.builders/topic/9708/module-help-for-variable</link><generator>RSS for Node</generator><lastBuildDate>Thu, 21 May 2026 19:19:47 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/9708.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 Feb 2019 17:10:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Module help for variable on Wed, 06 Feb 2019 00:05:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> Thanks, I got it. I needed to get rid of “this”.  So the correct test was:</p>
<pre><code>if (!(oldAwayState === awayState) &amp;&amp; (awayState === 'home')) 
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/51636</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/51636</guid><dc:creator><![CDATA[rts58]]></dc:creator><pubDate>Wed, 06 Feb 2019 00:05:13 GMT</pubDate></item><item><title><![CDATA[Reply to Module help for variable on Tue, 05 Feb 2019 22:24:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rts58" aria-label="Profile: rts58">@<bdi>rts58</bdi></a> the dev light is only for the module just file ( where getDom() is located)</p>
<p dir="auto">Debugging the node helper or included scripts needs the console.log.  sorry for confusion</p>
]]></description><link>https://forum.magicmirror.builders/post/51634</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/51634</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 05 Feb 2019 22:24:40 GMT</pubDate></item><item><title><![CDATA[Reply to Module help for variable on Tue, 05 Feb 2019 22:16:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> thanks, I’ll give that a try.  I’ve been writing the variables to the consol log but it’s not quite as helpful.</p>
]]></description><link>https://forum.magicmirror.builders/post/51633</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/51633</guid><dc:creator><![CDATA[rts58]]></dc:creator><pubDate>Tue, 05 Feb 2019 22:16:28 GMT</pubDate></item><item><title><![CDATA[Reply to Module help for variable on Tue, 05 Feb 2019 21:34:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rts58" aria-label="Profile: rts58">@<bdi>rts58</bdi></a> you can use the dev console and put stops in the code and look at the variables</p>
]]></description><link>https://forum.magicmirror.builders/post/51629</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/51629</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 05 Feb 2019 21:34:23 GMT</pubDate></item><item><title><![CDATA[Reply to Module help for variable on Tue, 05 Feb 2019 18:59:03 GMT]]></title><description><![CDATA[<p dir="auto">Is there something wrong with this:</p>
<pre><code>if (!(this.oldAwayState === awayState) &amp;&amp; (this.awayState === 'home')) 
</code></pre>
<p dir="auto">maybe they are both not strings or something?</p>
]]></description><link>https://forum.magicmirror.builders/post/51619</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/51619</guid><dc:creator><![CDATA[rts58]]></dc:creator><pubDate>Tue, 05 Feb 2019 18:59:03 GMT</pubDate></item><item><title><![CDATA[Reply to Module help for variable on Tue, 05 Feb 2019 18:47:57 GMT]]></title><description><![CDATA[<p dir="auto">That’s what I thought.  But it still fires off every two minutes, there must be an error in the logic.</p>
]]></description><link>https://forum.magicmirror.builders/post/51618</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/51618</guid><dc:creator><![CDATA[rts58]]></dc:creator><pubDate>Tue, 05 Feb 2019 18:47:57 GMT</pubDate></item><item><title><![CDATA[Reply to Module help for variable on Tue, 05 Feb 2019 18:19:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rts58" aria-label="Profile: rts58">@<bdi>rts58</bdi></a> this should work w your code as is</p>
]]></description><link>https://forum.magicmirror.builders/post/51613</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/51613</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 05 Feb 2019 18:19:05 GMT</pubDate></item><item><title><![CDATA[Reply to Module help for variable on Tue, 05 Feb 2019 18:04:50 GMT]]></title><description><![CDATA[<p dir="auto">Thank you <a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> !  So that helps me to create the module level variable.  Sorry for dumb question, but how to I read/write it from within my process data function?  I thought using <code>this.oldAwayState</code> would be the module level.</p>
]]></description><link>https://forum.magicmirror.builders/post/51612</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/51612</guid><dc:creator><![CDATA[rts58]]></dc:creator><pubDate>Tue, 05 Feb 2019 18:04:50 GMT</pubDate></item><item><title><![CDATA[Reply to Module help for variable on Tue, 05 Feb 2019 17:34:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rts58" aria-label="Profile: rts58">@<bdi>rts58</bdi></a> said in <a href="/post/51607">Module help for variable</a>:</p>
<pre><code>Module.register("controlMonitor", {
	defaults: {},
        oldAwayState: 'unknown',
        awayState: 'unknown',
	notificationReceived:
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/51611</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/51611</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 05 Feb 2019 17:34:10 GMT</pubDate></item></channel></rss>