Open olskar opened 5 years ago
I can certainly double that, would be great to get some more instruction on how to set this plugin up for a token authentication. Where do I have to put the token to?
I have not tried that, but maybe using whitelisting (https://www.home-assistant.io/docs/authentication/providers/) may work for a magic mirror use case, since all api accesses will come from the same IP address.
I did get it to work! I had to extra file containing the environmental variable which actually the starts the mm.sh script
I created a magic mirror.config.js in the same folder as the mm.sh
module.exports = {
apps : [
{
name: "MagicMirror",
script: "./mm.sh",
watch: true,
env: {
"HASSIO_TOKEN": "XXXXXXXXXXXX“
}
}
]
}
then I started the MM with
pm2 reload magic mirror.config.js
it works quite brilliantly
EDIT1: Changed the rotation mark according to chrismag1c (see below)
Sorry, I'm a newish to Magic Mirror. I've tried the HA Magic Mirror addon, and then running magic mirror from a Docker. I'm not sure how to approach the subject above. Where would i find the mm.sh?
I did get it to work! I had to extra file containing the environmental variable which actually the starts the mm.sh script
I created a magic mirror.config.js in the same folder as the mm.sh
module.exports = { apps : [ { name: "MagicMirror", script: "./mm.sh", watch: true, env: { "HASSIO_TOKEN": „XXXXXXXXXXXX“ } } ] }
then I started the MM with
pm2 reload magic mirror.config.js
it works quite brilliantly
Can you please post your config.js I tried that but I couldn't get it to work.
{
module: "MMM-HASS",
header: "Sensors",
position: "top_right",
config: {
host: "PUT IP HERE",
port: "8123",
apipassword: false,
hassiotoken: true,
https: false,
devices: [
{ deviceLabel: "WM",
deviceReadings: [
{ sensor: "sensor.wm", icon: "fa fa-plug", suffix: "W"}
]
},
{ deviceLabel: "3D-Printer",
deviceReadings: [
{ sensor: "sensor.printer", icon: "fa fa-print", suffix: "%",}
]
},
{ deviceLabel: "Plant A",
deviceReadings: [
{ sensor: "sensor.a", icon: "wi wi-humidity", suffix: "%"}
]
},
{ deviceLabel: "Plant B",
deviceReadings: [
{ sensor: "sensor.b", icon: "wi wi-humidity", suffix: "%"}
]
},
{ deviceLabel: "Plant C",
deviceReadings: [
{ sensor: "sensor.c", icon: "wi wi-humidity", suffix: "%"}
]
},
{ deviceLabel: "Plant D",
deviceReadings: [
{ sensor: "sensor.d", icon: "wi wi-humidity", suffix: "%",}
]
}
]
}
}
@Kugelfang666 so I created the mirror.config.js file and copied your code and saved the file in the directory where the mm.sh is i.e. my home folder.
I then added your above code to my config.js and when I restart my mm using "pm2 restart mm" I get invalid config.
What have you done differently to mine?
@bachoo786:
also I just realized I missed one } in the code I posted. please check your config
Is this for hassio or long lived tokens?
I created a user within the home assistant GUI dedicated for the magic mirror. For this very user I retrieved the long lived token and put it into the environmental variable list
So you are not using hassio?
I'm using hassio on a raspberry pi
Ok I am running HA on docker
ok, but does it make a difference on how this plugin interacts with home assistant?
I don't think so
I did get it to work! I had to extra file containing the environmental variable which actually the starts the mm.sh script
I created a magic mirror.config.js in the same folder as the mm.sh
module.exports = { apps : [ { name: "MagicMirror", script: "./mm.sh", watch: true, env: { "HASSIO_TOKEN": „XXXXXXXXXXXX“ } } ] }
then I started the MM with
pm2 reload magic mirror.config.js
it works quite brilliantly
yes it works, thanks. Please consider to use the right quotation marks for the token. I copied the code from here and didn't notice. It should be "HASSIO_TOKEN": "XXXXXXXXXXXX" instead of „XXXXXXXXXXXX“.
I created a new magic.config.js (MagicMirror/installers) with the content from above. I stopped mm: pm2 stop mm
And started: pm2 start magic.config.js
thanks for the finding, I must have screwed up the "" when removing my token, thanks for the finding. I edited my original post accordingly!
I did get it to work! I had to extra file containing the environmental variable which actually the starts the mm.sh script
I created a magic mirror.config.js in the same folder as the mm.sh
module.exports = { apps : [ { name: "MagicMirror", script: "./mm.sh", watch: true, env: { "HASSIO_TOKEN": "XXXXXXXXXXXX“ } } ] }
then I started the MM with
pm2 reload magic mirror.config.js
it works quite brilliantly
EDIT1: Changed the rotation mark according to chrismag1c (see below)
sorry, I don not have mm.sh file. I only have a run-start.sh file in the MagicMirror folder. and it contains these code: if [ -z "$DISPLAY" ]; then #If not set DISPLAY is SSH remote or tty export DISPLAY=:0 # Set by default display fi electron js/electron.js $1
I usually use the command "npm start "to run magic mirror. Can you tell me more details?
i see, I just updated my MM and in the newer releases it works a bit different: in \MagicMirror\installers
I changed the pm2-MagicMirror.json to look like this:
{
"apps" : [{
"name" : "MagicMirror",
"script" : "/home/pi/MagicMirror/installers/mm.sh",
"watch" : ["/home/pi/MagicMirror/config/config.js"],
"env" : {
"HASSIO_TOKEN": "YOUR TOKEN HERE",
}
}]
}
then I created a new file in the same folder called mm.sh which noch contains:
cd ~/MagicMirror
DISPLAY=:0 npm start
this way pm2 starts the first file which contains the token. In turn this file then starts the mm.sh wich initiates the magidmirror.
@Kugelfang666 I have absolutely the same setup as yours but I still get only up to the point where the module is loaded but it keeps on “Loading” in MM
I do have the long lasting token in HA set up and copied to pm2-MagicMirror.json
However my HA is only accessed via HTTPS, so the only change in my config is that https is true not false, however I tried both true and false and it still fails.
Any thoughts?
I’ve made some progress after following the instructions in https://github.com/aserramonner/MMM-HASS/issues/8
Now the module loads the sensors names, but the readings are “undefined” …
The HA log shows “Login attempt or request with invalid authentication from XXX.XXX.X.X (the IP of the MM)”, however the LL token is correct. I deleted and created a new one and copy-pasted it in the json … don’t know what is going wrong...
very wired. did you create a dedicated user for the mirror? if not try it. It could be that HASSIO does not like the identical user being logged in via different machines.
What I did was to create a dedicated user on my HA. then I logged in as such and created a new permanent token
Yeah, I thought the same then I read through the whole topic again and noticed that you have separate accounts and tried that as well - didn't work ...
I think SSL is what breaks things ...
Are you using a self signed certificate or letsencypt? And did you try without ssl?
I am using LetsEncrypt in the DuckDNS addon.
Here is my starting point as of now:
configuration.yaml
http:
base_url: https://XXXXXX.duckdns.org
ssl_certificate: /ssl/fullchain.pem
ssl_key: /ssl/privkey.pem
api_password: !secret http_password #I use this for IFTTT recipies that triger scripts
ssl_profile: intermediate
DuckDNS config:
{
"lets_encrypt": {
"accept_terms": true,
"certfile": "fullchain.pem",
"keyfile": "privkey.pem"
},
"token": "XXXXXXXXX",
"domains": [
"XXXXXX.duckdns.org"
],
"seconds": 300
}
pm2_MagicMirror.json
~/MagicMirror/installers $ cat pm2_MagicMirror.json
{
"apps" : [{
"name" : "MagicMirror",
"script" : "/home/pi/MagicMirror/installers/mm.sh",
"watch" : ["/home/pi/MagicMirror/config/config.js"],
"env" : {
"HASSIO_TOKEN": "XXXXXXXXX"
}
}]
}
config.js
{
module: "MMM-HASS",
header: "Сензори",
position: "top_left",
config: {
host: "192.168.1.19", // I have tried hassio.local xxxxx.duckdns.org as well
port: "8123",
apipassword: false,
hassiotoken: true,
https: true,
devices: [
{ deviceLabel: "Температура",
deviceReadings: [
{ sensor: "sensor.temperature_158d000273cb7c", icon: "fa fa-temperature-high", suffix: " C"}
]
},
{ deviceLabel: "Влажност",
deviceReadings: [
{ sensor: "sensor.humidity_158d000273cb7c", icon: "fa fa-humidity", suffix: " %",}
]
},
{ deviceLabel: "Налягане",
deviceReadings: [
{ sensor: "sensor.pressure_158d000273cb7c", icon: "fa fa-cloudscale", suffix: " hPa"}
]
}
]
}
},
I will keep trying without the SSL and DuckDNS to see if that makes difference and will report later.
Thanks for the support @Kugelfang666
I am getting the following error in the pm2 logs on MM no matter if I use SSL or not:
TypeError: Cannot read property 'entity_id' of undefined
at Request._callback (/home/pi/MagicMirror/modules/MMM-HASS/node_helper.js:185:26)
at self.callback (/home/pi/MagicMirror/modules/MMM-HASS/node_modules/request/request.js:185:22)
at Request.emit (events.js:182:13)
at Request.onRequestError (/home/pi/MagicMirror/modules/MMM-HASS/node_modules/request/request.js:881:8)
at ClientRequest.emit (events.js:182:13)
at TLSSocket.socketErrorListener (_http_client.js:382:9)
at TLSSocket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
ATTENTION: default value of option force_s3tc_enable overridden by environment.
(node:20699) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
the configuration of the pm2 file and the config.js looks ok to me,
maybe just a simple question: from the error message I would assume that the actual connection is ok. did you try polling another sensor?
Beyond this I'm afraid thy my expertise ends here :-)
one more thing: does the SSL protocol also listen to port 8123??
@Kugelfang666 yeah I am out of ideas as well ...
The connection is fine, I can see that MM is trying to pull the data from HA but fails to authenticate, so trying any other sensor also fails. I am sure that there is something fishy with the authentication but don't know what ... I tried with and without SSL, same thing ... I updated the module, raspbian, HA ... everything is up-to-date but still:
I will leave that for now :) If I get inspired another day I will try harder to solve this :D
Thanks for your input though :)
Maybe it helps others in my situation. I run MM in a docker container in server-only mode. For this, add
-e HASSIO_TOKEN="XXXXXXXXXX"
to your docker command (instead of adding it to the pm2 json).
[03:20:26.810] [ERROR] Error: Cannot find module 'underscore'
at Module._resolveFilename (internal/modules/cjs/loader.js:602:15)
at Function.Module._resolveFilename (/home/pi/MagicMirror/node_modules/electron/dist/resources/electron.asar/common/reset-search-paths.js:35:12)
at Function.Module._resolveFilename (/home/pi/MagicMirror/node_modules/module-alias/index.js:49:29)
at Function.Module._load (internal/modules/cjs/loader.js:528:25)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.
@Kugelfang666 yeah I am out of ideas as well ...
The connection is fine, I can see that MM is trying to pull the data from HA but fails to authenticate, so trying any other sensor also fails. I am sure that there is something fishy with the authentication but don't know what ... I tried with and without SSL, same thing ... I updated the module, raspbian, HA ... everything is up-to-date but still:
I will leave that for now :) If I get inspired another day I will try harder to solve this :D
Thanks for your input though :)
After some Time I had to reset my token and ran into the same problem. After some digging I found the solution: There seems to be a bug so that pm2 does not read the pm2_MagicMirror.json correctly. SSH into the MM and going into the installers Folger I ran pm2 reload pm2_MagicMirror.json and the problem was gone
Replace line 130 in hode_helper.js with: post_options.headers = { 'Authorization' : 'Bearer ' + config.token }; and line 175 in node_helper.js with: get_options.headers = { 'Authorization' : 'Bearer ' + config.token };
Then add a token parameter to your config:
{
module: "MMM-HASS",
position: "top_left",
config: {
host: "serverip",
port: "8123",
hassiotoken: true,
token: "redacted",
https: false,
devices: [
{ deviceLabel: "Ude",
deviceReadings: [
{ sensor: "sensor.ude_zb_temperature", icon: "wi wi-thermometer", suffix: "°"},
{ sensor: "sensor.ude_zb_humidity", icon: "wi wi-humidity", suffix: "%"},
{ sensor: "sensor.ude_min", icon: "wi wi-thermometer", su""}
]
},
{ deviceLabel: "Inde",
deviceReadings: [
{ sensor: "sensor.alrum_motion_temperature", icon: "wi wi-thermometer", suffix: "°", notification: "INDOOR_TEMPERATURE"}
]
}
]
}
},
Then just install with npm install and no need for environment parameters :)
Maybe it helps others in my situation. I run MM in a docker container in server-only mode. For this, add
-e HASSIO_TOKEN="XXXXXXXXXX"
to your docker command (instead of adding it to the pm2 json).
legend. Here we are in 2022, needing to apply work arounds.
Since api password is being removed from Home Assistant, How to use without API-password?