<?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[Display image based on state or time]]></title><description><![CDATA[<p dir="auto">Hey, I want to display an image (or rather an icon) showing when I’m being billed by my power company at either peak, off peak or night rates. So an if then else condition, either by time of day or alternately because I have that state known already in home assistant then either by mqtt or restful api.</p>
<p dir="auto">I’ve googled searched and also scrolled through the modules and can find some things that do half the job or combined could probably hack it, but want to know is there a conditional module available that will do this easily? If not what’s the best method to achieve this?</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.magicmirror.builders/topic/17922/display-image-based-on-state-or-time</link><generator>RSS for Node</generator><lastBuildDate>Thu, 11 Jun 2026 03:51:16 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/17922.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 23 Jul 2023 10:57:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Display image based on state or time on Tue, 25 Jul 2023 17:44:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chimera" aria-label="Profile: chimera">@<bdi>chimera</bdi></a> Hi and sure,</p>
<p dir="auto">just tested a config which uses the values send by MQTT directly to decide which icon to display:</p>
<pre><code>var mqttHook = [
    {
      mqttTopic: "magicmirror/tarrif/set",
      mqttPayload: [
        {
          mqttNotiCmd: ["energy_tarrif_value"]
        }
      ]
    }
  ];
var mqttNotiCommands = [
    {
      commandId: "energy_tarrif_value",
      notiID: "ENERGY_TARRIF"
    }
  ];

  module.exports = { mqttHook,  mqttNotiCommands};
</code></pre>
<pre><code>{
	module: "MMM-MQTTbridge",
	disabled: false,
	config: {
		mqttServer: "mqtt://my_user:my_pass@my_server:the_port",
		mqttConfig: {
			listenMqtt: true,
		},
	}
},
{
	module: "MMM-ValuesByNotification",
	position: "top_left",
	header: "Energy",
	config: {
		updateInterval: 10,
		reuseCount: 90,
		valuePositions: "i",
		valueNaPositions: "i",
		itemPositions: "e",
		groupPositions: "e",
		groups: [
			{
				items: [
					{
						notification: "ENERGY_TARRIF",
						valueImgIcon: "modules/MMM-ValuesByNotification/icons/tom.jpg",
						values: [
							{
								jsonpath: "state",
								thresholds: [
									{
										type: "eq",
										value: "PEAK",
										valueImgIcon: "modules/MMM-ValuesByNotification/icons/peak.jpg",
									},
									{
										type: "eq",
										value: "OFF-PEAK",
										valueImgIcon: "modules/MMM-ValuesByNotification/icons/off-peak.jpg",
									},
									{
										type: "eq",
										value: "NIGHT",
										valueImgIcon: "modules/MMM-ValuesByNotification/icons/night.jpg",
									},
								]
							},
						]
					},
				]
			},
		]
	},
},
</code></pre>
<p dir="auto">Explanation…</p>
<p dir="auto">MMM-MQTTbridge:</p>
<ul>
<li>The module connects to the MQTT-Server <code>my_server</code> to port <code>the_port</code> with user <code>my_user</code> and password <code>my_pass</code></li>
<li>As <code>listenMqtt</code> is set to <code>true</code> the settings in <code>mqttDictionary.js</code> are used which results in:
<ul>
<li>If a message to <code>mqttTopic</code> <code>magicmirror/tarrif/set</code> is received the message is processed by the <code>mqttNotiCmd</code> <code>energy_tarrif_value</code></li>
<li>As no <code>payloadValue</code> is specified the command is called independent of the message that is send to the topic</li>
<li>As no <code>notiPayload</code> is set in the command configuration but the <code>notiID</code> <code>ENERGY_TARRIF</code> every time a message is received of the specified topic a notification is send to all other modules with notification id <code>ENERGY_TARRIF</code> and the original MQTT message as payload</li>
</ul>
</li>
</ul>
<p dir="auto">MMM-ValuesByNotification:</p>
<ul>
<li>the module refreshes every ten seconds as <code>updateInterval</code> is set to <code>10</code></li>
<li>if no new notification is received for a configured <code>notification</code> of a item but the module refreshes it will reuse the last received value for a maximum of 90 times (<code>reuseCount</code>)</li>
<li>As <code>valuePositions</code> and <code>valueNaPositions</code> are set to <code>i</code> only a specified icon will be displayed instead of the value itself (which will be <code>v</code> or if both should be displayed <code>vi</code>; see <a href="https://github.com/Tom-Hirschberger/MMM-ValuesByNotification/blob/main/doc/positions.md" target="_blank" rel="noopener noreferrer nofollow ugc">Positions-Documentation</a> for more info)</li>
<li>As <code>itemPositions</code> and <code>groupPositions</code> are both set to <code>e</code> only the elements and no additional titles (<code>t</code>) or icons (<code>i</code>) are displayed ( see <a href="https://github.com/Tom-Hirschberger/MMM-ValuesByNotification/blob/main/doc/positions.md" target="_blank" rel="noopener noreferrer nofollow ugc">Positions-Documentation</a> for more info)</li>
<li>A single group with one item which contains one value is specified</li>
<li>The values of the item use the payload of the notification with id <code>ENERGY_TARRIF</code></li>
<li>As default icon a image for the value (<code>valueImgIcon</code>) is used which has the path <code>modules/MMM-ValuesByNotification/icons/tom.jpg</code> (see <a href="https://github.com/Tom-Hirschberger/MMM-ValuesByNotification/blob/main/doc/icons.md" target="_blank" rel="noopener noreferrer nofollow ugc">Icon-Documentation</a> for more details)</li>
<li>The value element selects the content with <code>jsonpath</code> <code>state</code> as its value. This means the payload of the notification is parsed as JSON and the value which is used in further processing is the content of the <code>state</code> element. This can be everything the HomeAssistant sends but should be either <code>PEAK</code>, <code>OFF_PEAK</code> or <code>NIGHT</code></li>
<li>As there are <code>thresholds</code> specified they are validated against the previously selected <code>state</code>
<ul>
<li>If the payload is equal to (<code>eq</code>) to the <code>value</code> <code>PEAK</code> the path of the <code>valueimgIcon</code> is changed to <code>modules/MMM-ValuesByNotification/icons/peak.jpg</code></li>
<li>If the payload is equal to (<code>eq</code>) to the <code>value</code> <code>OFF_PEAK</code> the path of the <code>valueimgIcon</code> is changed to <code>modules/MMM-ValuesByNotification/icons/off-peak.jpg</code></li>
<li>If the payload is equal to (<code>eq</code>) to the <code>value</code> <code>NIGHT</code> the path of the <code>valueimgIcon</code> is changed to <code>modules/MMM-ValuesByNotification/icons/night.jpg</code></li>
</ul>
</li>
</ul>
<p dir="auto">Directly after the start the MMM-ValuesByNotification module will display the default icon. Every 10 seconds it refreshes. If a message for the specified topic is received by MMM-MQTTbridge the notification is send. The next time the module refreshes it will validate the message content and changes the icon depending on the content.</p>
]]></description><link>https://forum.magicmirror.builders/post/110363</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/110363</guid><dc:creator><![CDATA[wishmaster270]]></dc:creator><pubDate>Tue, 25 Jul 2023 17:44:42 GMT</pubDate></item><item><title><![CDATA[Reply to Display image based on state or time on Mon, 24 Jul 2023 22:41:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wishmaster270" aria-label="Profile: wishmaster270">@<bdi>wishmaster270</bdi></a> For my own understanding (and possibly others) I’d still like to know how notifications work in your module, what variable determines the payload?  How would I select an image based on a notification from the MQTTbridge?  I see your example uses code to return a variable based on time of day, but if that comes in via notifications instead how would one display the correct image?</p>
]]></description><link>https://forum.magicmirror.builders/post/110360</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/110360</guid><dc:creator><![CDATA[chimera]]></dc:creator><pubDate>Mon, 24 Jul 2023 22:41:26 GMT</pubDate></item><item><title><![CDATA[Reply to Display image based on state or time on Mon, 24 Jul 2023 14:10:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chimera" aria-label="Profile: chimera">@<bdi>chimera</bdi></a> Hi and no problem, great you found a solution. My modules are much more complicated in this situation.</p>
]]></description><link>https://forum.magicmirror.builders/post/110357</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/110357</guid><dc:creator><![CDATA[wishmaster270]]></dc:creator><pubDate>Mon, 24 Jul 2023 14:10:13 GMT</pubDate></item><item><title><![CDATA[Reply to Display image based on state or time on Mon, 24 Jul 2023 11:22:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wishmaster270" aria-label="Profile: wishmaster270">@<bdi>wishmaster270</bdi></a> Thanks anyway and nevermind, I use MMM-MQTT already and found this to be considerably easier using the ‘conversions’ functionality…</p>
<pre><code>{
			module: 'MMM-MQTT',
			position: 'top_right',
			header: 'ENERGY TARRIF',
			config: {
				logging: false,
				useWildcards: false,
				mqttServers: [
					{
						address: '192.168.222.100',
						port: '1883',
						user: 'mqtt',
						password: 'password,
						subscriptions: [
							{
								topic: "magicmirror/tarrif/set",
								maxAgeSeconds: 60,
								label: "",
								conversions: [
								  {
									from: "PEAK",
									to: "&lt;img src='modules/default/icons/peak.png' width=80px&gt;",
								  },
								  {
									from: "OFF-PEAK",
									to: "&lt;img src='modules/default/icons/offpeak.png' width=80px&gt;",
								  },
								  {
									from: "NIGHT",
									to: "&lt;img src='modules/default/icons/night.png' width=80px&gt;",
								  },
								  {
									from: "",
									to: "#DISABLED#",
								  },
								]
							}
						]
					}
				],
			}
		},
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/110356</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/110356</guid><dc:creator><![CDATA[chimera]]></dc:creator><pubDate>Mon, 24 Jul 2023 11:22:07 GMT</pubDate></item><item><title><![CDATA[Reply to Display image based on state or time on Mon, 24 Jul 2023 05:54:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wishmaster270" aria-label="Profile: wishmaster270">@<bdi>wishmaster270</bdi></a> thanks, but I’m really confused by the notifications side.</p>
<p dir="auto">I’ve setup mqttDictionary.js</p>
<pre><code>var mqttHook = [
    {
      mqttTopic: "magicmirror/tarrif/set",
      mqttPayload: [
        {
          payloadValue: '{"state": "PEAK"}',
          mqttNotiCmd: ["Command PEAK"]
        },
        {
          payloadValue: '{"state": "OFF-PEAK"}',
          mqttNotiCmd: ["Command OFF-PEAK"]
        },
        {
          payloadValue: '{"state": "NIGHT"}',
          mqttNotiCmd: ["Command NIGHT"]
        },
      ],
    },
  ];
var mqttNotiCommands = [
    {
      commandId: "Command PEAK",
      notiID: "ENERGY_TARRIF",
      notiPayload: {action: 'PEAK'}
    },
    {
      commandId: "Command OFF-PEAK",
      notiID: "ENERGY_TARRIF",
      notiPayload: {action: 'OFF-PEAK'}
    },
    {
      commandId: "Command NIGHT",
      notiID: "ENERGY_TARRIF",
      notiPayload: {action: 'NIGHT'}
    },  
  ];

  module.exports = { mqttHook,  mqttNotiCommands};
</code></pre>
<p dir="auto">So ‘magicmirror/tarrif/set’ topic gets set to either PEAK, OFF-PEAK or NIGHT via Home Assistant mqtt publish action, and the above sees this then this sets the notification payload to send.</p>
<p dir="auto">What I don’t understand is how to display the appropriate .png file using your module.  I assume <strong>notification: “ENERGY_TARRIF”</strong> relates to the notification ID in the dictionary  (?) but what relates to the payload?  Based on your example I assumed it would be, eg: <strong>value: “PEAK”</strong> with the valueImgIcon underneath but that doesn’t work.</p>
<p dir="auto">I just get all 3 images showing with NA underneath.</p>
]]></description><link>https://forum.magicmirror.builders/post/110355</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/110355</guid><dc:creator><![CDATA[chimera]]></dc:creator><pubDate>Mon, 24 Jul 2023 05:54:47 GMT</pubDate></item><item><title><![CDATA[Reply to Display image based on state or time on Sun, 23 Jul 2023 17:47:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chimera" aria-label="Profile: chimera">@<bdi>chimera</bdi></a> Hi, you may be able to use my <a href="https://github.com/Tom-Hirschberger/MMM-ValuesByNotification" target="_blank" rel="noopener noreferrer nofollow ugc">MMM-ValuesByNotification</a> for this job.<br />
It is a little hack but i tested it and it seems to work.</p>
<p dir="auto">The basic idea of the module is to display values send by notifications of other modules<br />
BUT<br />
the module has the ability to display a default value (<code>naValue</code>) if no value has been send by any other module. It has abilities to display icons instead the value and change the icons based on thresholds (conditions). In combination with the support to define functions to format the values before the check of the conditions it will be possible to get the current time:</p>
<pre><code>{
	module: "MMM-ValuesByNotification",
	position: "top_left",
	header: "Energy",
	config: {
		updateInterval: 60,
		valuePositions: "i",
		valueNaPositions: "i",
		itemPositions: "e",
		groupPositions: "e",
		formatNaValue: true,
		transformerFunctions: {
			naToImgIdent: (value) =&gt; {
				let curHour = new Date().getHours();
				if ((curHour &gt;= 0) &amp;&amp; (curHour &lt;= 6)){
					//From 0 to 6 o clock
					return "a"
				} else if ((curHour &gt;= 7) &amp;&amp; (curHour &lt;= 12)) {
					//From 7 to 12 o clock
					return "b"
				}  else if ((curHour &gt;= 13) &amp;&amp; (curHour &lt;= 18)) {
					//From 13 to 18 o clock
					return "c"
				} else {
					//From 19 to 23 o clock
					return "d" 
				}
			}
		},
		groups: [
			{
				items: [
					{
						notification: "ICON_DUMMY_ABC",
						valueImgIcon: "modules/MMM-ValuesByNotification/icons/tom.jpg",
						values: [
							{
								valueTransformers: ["naToImgIdent"],
								thresholds: [
									{
										type: "eq",
										value: "a",
										valueImgIcon: "modules/MMM-ValuesByNotification/icons/tom.jpg",
									},
									{
										type: "eq",
										value: "b",
										valueImgIcon: "modules/MMM-ValuesByNotification/icons/tom2.jpg",
									},
									{
										type: "eq",
										value: "c",
										valueImgIcon: "modules/MMM-ValuesByNotification/icons/tom.jpg",
									},
									{
										type: "eq",
										value: "d",
										valueImgIcon: "modules/MMM-ValuesByNotification/icons/tom2.jpg",
									},
								]
							},
						]
					},
				]
			},
		]
	},
},
</code></pre>
<p dir="auto">Edit:<br />
I should have read your question in detail first :-)<br />
If you can provide the state via MQTT already you can for sure use this module. You will need <a href="https://github.com/Tom-Hirschberger/MMM-MQTTbridge" target="_blank" rel="noopener noreferrer nofollow ugc">MMM-MQTTbridge</a> to send the value as payload of a notification. Check for the notification in <a href="https://github.com/Tom-Hirschberger/MMM-ValuesByNotification" target="_blank" rel="noopener noreferrer nofollow ugc">MMM-ValuesByNotification</a> and display the icon you like.</p>
]]></description><link>https://forum.magicmirror.builders/post/110352</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/110352</guid><dc:creator><![CDATA[wishmaster270]]></dc:creator><pubDate>Sun, 23 Jul 2023 17:47:23 GMT</pubDate></item></channel></rss>