@wishmaster270 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?
Read the statement by Michael Teeuw here.
Posts
-
RE: Display image based on state or time
-
RE: Display image based on state or time
@wishmaster270 Thanks anyway and nevermind, I use MMM-MQTT already and found this to be considerably easier using the ‘conversions’ functionality…
{ 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: "<img src='modules/default/icons/peak.png' width=80px>", }, { from: "OFF-PEAK", to: "<img src='modules/default/icons/offpeak.png' width=80px>", }, { from: "NIGHT", to: "<img src='modules/default/icons/night.png' width=80px>", }, { from: "", to: "#DISABLED#", }, ] } ] } ], } },
-
RE: Display image based on state or time
@wishmaster270 thanks, but I’m really confused by the notifications side.
I’ve setup mqttDictionary.js
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};
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.
What I don’t understand is how to display the appropriate .png file using your module. I assume notification: “ENERGY_TARRIF” relates to the notification ID in the dictionary (?) but what relates to the payload? Based on your example I assumed it would be, eg: value: “PEAK” with the valueImgIcon underneath but that doesn’t work.
I just get all 3 images showing with NA underneath.
-
Display image based on state or time
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.
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?
Thanks
-
RE: MMM-MQTTbridge
This is perfect!!! Thanks so much! I run OpenHAB and utilise MQTT quite heavily. However I don’t like MQTT persistence, as it doesn’t work for me in OpenHAB. I run MMM-MQTT module in MM, but the problem with that is, when MagicMirror starts up it doesn’t display MQTT topic payload, as many MQTT updates I get are on intermittent basis (eg: swimming pool temperature, only updates if it changes, garden sprinkler last run, only updates when it’s run etc) So I’ve used this with MMM-Pages (I have several MM screens) and the 2nd page has mostly OpenHAB related info that I want to display. So I use the Notification ‘PAGE_CHANGED’ with payload = 1 (as pages start from 0) to publish an MQTT message of openhab/magicmirror/requestmqtt = ON. This is tied to a switch item in OpenHAB, and a rule in OpenHAB detects when the switch gets turned on, and in turn publishes a list of latest home automation data out to MQTT, which gets picked up and displayed on Magic Mirror. Prior to this, I would have a lot of items with “updating…” and had to wait until the device sent its latest information to MQTT.
This covers all bases and more. I can see this becoming a very powerful little module!
Thanks again!