MMM-HASS icon indicating copy to clipboard operation
MMM-HASS copied to clipboard

How to use without API-password?

Open olskar opened this issue 6 years ago • 34 comments

Since api password is being removed from Home Assistant, How to use without API-password?

olskar avatar Dec 01 '18 15:12 olskar

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?

Kugelfang666 avatar Dec 06 '18 17:12 Kugelfang666

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.

aserramonner avatar Dec 06 '18 20:12 aserramonner

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)

Kugelfang666 avatar Dec 06 '18 20:12 Kugelfang666

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?

prosonik avatar Dec 15 '18 16:12 prosonik

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.

ivanovd avatar Dec 20 '18 00:12 ivanovd

{
                 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 avatar Dec 24 '18 11:12 Kugelfang666

@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 avatar Dec 29 '18 23:12 bachoo786

@bachoo786:

  • did you put the IP address of your HASSIO instance into the config code?
  • did you put an actual long lasting token into the mirror.config.js?

also I just realized I missed one } in the code I posted. please check your config

Kugelfang666 avatar Dec 30 '18 08:12 Kugelfang666

Is this for hassio or long lived tokens?

bachoo786 avatar Dec 30 '18 10:12 bachoo786

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

Kugelfang666 avatar Dec 30 '18 10:12 Kugelfang666

So you are not using hassio?

bachoo786 avatar Dec 30 '18 11:12 bachoo786

I'm using hassio on a raspberry pi

Kugelfang666 avatar Dec 30 '18 13:12 Kugelfang666

Ok I am running HA on docker

bachoo786 avatar Dec 30 '18 13:12 bachoo786

ok, but does it make a difference on how this plugin interacts with home assistant?

Kugelfang666 avatar Dec 30 '18 13:12 Kugelfang666

I don't think so

bachoo786 avatar Dec 30 '18 13:12 bachoo786

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

chrismag1c avatar Jan 03 '19 22:01 chrismag1c

thanks for the finding, I must have screwed up the "" when removing my token, thanks for the finding. I edited my original post accordingly!

Kugelfang666 avatar Jan 03 '19 22:01 Kugelfang666

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?

wangjiwang avatar Apr 03 '19 12:04 wangjiwang

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 avatar Apr 07 '19 11:04 Kugelfang666

@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?

ivanovd avatar Apr 08 '19 08:04 ivanovd

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...

ivanovd avatar Apr 08 '19 09:04 ivanovd

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

Kugelfang666 avatar Apr 08 '19 22:04 Kugelfang666

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 ...

MaxthonSnap20190409100820

I think SSL is what breaks things ...

ivanovd avatar Apr 09 '19 07:04 ivanovd

Are you using a self signed certificate or letsencypt? And did you try without ssl?

Kugelfang666 avatar Apr 09 '19 08:04 Kugelfang666

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

ivanovd avatar Apr 09 '19 11:04 ivanovd

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.

ivanovd avatar Apr 09 '19 11:04 ivanovd

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 :-)

Kugelfang666 avatar Apr 09 '19 16:04 Kugelfang666

one more thing: does the SSL protocol also listen to port 8123??

Kugelfang666 avatar Apr 09 '19 16:04 Kugelfang666

@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: MaxthonSnap20190409192757

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 :)

ivanovd avatar Apr 09 '19 16:04 ivanovd

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).

ax42 avatar Nov 07 '19 12:11 ax42