MiniMote + Vera

Has anyone set up a minimote using a vera hub? I can’t seem to get it working right.

When I add it, Home Assistant sees it as a sensor. When I press a button I get an event, but it’s very delayed and not exactly what I was expecting:

INFO:homeassistant.core:Bus:Handling <Event state_changed[L]: old_state=<state sensor.minimote_20=unknown; friendly_name=MiniMote, Vera Device Id=20 @ 2017-05-25T01:04:54.568673-04:00>, new_state=<state sensor.minimote_20=1; friendly_name=MiniMote, Vera Device Id=20 @ 2017-05-25T01:15:15.413166-04:00>, entity_id=sensor.minimote_20>

Also, when I press a button, both the blue and red LEDs light up.

I’m hoping that someone else has gone this route and could provide some help on exactly how to set it up to send zwave.scene_activated events. Thanks!

Update: I figured out that I was going about it all wrong with it being paired with a Vera Bridge. Read below to see how I did it. Spoiler: it works great and is instant!

Do you have a Zwave modem on your HA install? When I moved from Vera to HA, I moved most Zwave items to HA.

Not sure if it’s what you’re looking for, but for a while, I was using helper scripts in Vera to communicate with HA’s API. Put something like this in your LUA:

function ha_api(endpoint,payload) {
-- endpoint like automation/trigger
-- payload like {"entity_id":"automation.garage_doors_trigger_lights"}
	local https = require 'ssl.https'
	local ltn12 = require 'ltn12'

	local request_body = payload
	local response_body = {}

	b, c, h = https.request {
	  
	  url = 'https://YOURIP/api/services/' .. endpoint .. '?api_password=password',
	  method = 'POST',
	  headers = {
	    ["Content-Type"] =  "application/json",
			["Content-Length"] = string.len(request_body)
		},
	  source = ltn12.source.string(request_body),
	  sink = ltn12.sink.table(response_body),
	}

end

Ha, thanks so much for helping!

I realized late last night that I was being dumb. Of course those events weren’t coming across, I’m not using Zwave native to Home Assistant :roll_eyes:

Once I realized that, I knew I’d have to work inside of Vera. After failing at faking things with virtual switches (these don’t seem to be exposed with the Vera component) I realized I could just make HTTP calls with scenes.

So, the buttons trigger scenes, which run the LUA, just like you had said. Boom, instant reactions.

I’m going to write up how I did it later today.

Here’s what I came up with to get a fast reaction from the MiniMote while having it paired with a Vera bridge.

First off, don’t bother with the SceneController support that was recently added. It uses polling and it’s slow. The whole point of a remote is to get instant reaction. The solution is to just make native Vera scenes that send API calls to Home Assistant, have have the MiniMote trigger those. Here’s how I did it.

*This assumes you’ve already paired your MiniMote (it’s easy) and you’re on the latest Vera firmware.

In Vera

  1. Create a scene.
  2. For a trigger, pick Manual
  3. Ignore actions, just skip that step and go straight to Step 3 of the scene wizard.
  4. In step 3, pick Also, execute the following Luup code and add the code below.
  5. Finally, name it after a button: MiniMote Button 1.

Lua Code

  1. Paste the below code into the field and replace the IP address with your Home Assistant’s IP address.
  2. Replace the password too.
local http = require "socket.http"

http.timeout = 5 
local  body, code, headers, status = http.request {
  method = "POST",
  url = "http://192.168.1.10:8123/api/events/minimote_button_1",
  headers = { ["x-ha-access"] = "YOURPASSWORD" }
}

The event name in the URL is what you’ll listen for in your automation in Home Assistant.

Now, do this all over again, except name the scene MiniMote Button 1 Hold and change the event name to something like minimote_button_1. Now you have a scene to trigger when you hold a button on your MiniMote too.

Do this for all 4 of your buttons (you should end up with 8 scenes.)

Add scenes to button on your MiniMote

Now, go to your MiniMote and select Select scenes for device buttons. Assign the scenes to your buttons.

Now when you click these buttons, they will send these events to your Home Assistant. You should see this in your logs:

INFO:homeassistant.components.http:Serving /api/events/minimote_button_1 to 192.168.1.119 (auth: True)

If you see that, you know it’s working.

In Home Assistant

Now add some automations that listen for these events.

- alias: Minimote Button 1 Pressed
  trigger:
    platform: event
    event_type: minimote_button_1
  action:
    - service: light.turn_on
      data:
          entity_id: "light.bedroom"

- alias: Minimote Button 1 Held
  trigger:
    platform: event
    event_type: minimote_button_1_hold
  action:
    - service: light.turn_off
      data:
          entity_id: "light.bedroom"

Voila! now you can pair your MiniMote with Vera and have the same fast reaction times that you should expect.

3 Likes

@ih8gates are you still using this? I would love to replace the API access with webhooks/long lived acces tokens.

Nope - gave up on Vera a while ago. You’ll need to figure out how to pass the token as a header from Lua. Sorta like @maddox touches on above.

In step 2 of the this tutorial to get Tasker to talk to HA, they set show how to set the token. You need an Authorize token with a value of “Bearer YOURPASSWORD”

You just need to research the LUA equivalent.

Ok, thanks. That’s a pity. I’ll study the tasker solution but afraid I’m way over my head here…

It’s going to be something like:

function ha_api(endpoint,payload) {
-- endpoint like automation/trigger
-- payload like {"entity_id":"automation.garage_doors_trigger_lights"}
	local https = require 'ssl.https'
	local ltn12 = require 'ltn12'

	local request_body = payload
	local response_body = {}

	b, c, h = https.request {
	  
	  url = 'https://YOURIP/api/services/' .. endpoint,
	  method = 'POST',
	  headers = {
	    ["Content-Type"] =  "application/json",
	    ["Content-Length"] = string.len(request_body),
            ["Authorization"] = "Bearer YOURTOKEN"
		},
	  source = ltn12.source.string(request_body),
	  sink = ltn12.sink.table(response_body),
	}

end
1 Like

Cool. Let me test this when I’m home (on the slopes now). Thanks!

@ih8gates Hi Scott, I have been putting this off for too long. Now .101 actually breaks the old method fully. Have you ever had to migrate?

Nah - I chucked my Vera long ago.

But that example should work. You pass the token in the header as illustrated. I’m doing similar with Tasker.

Got it working by trail and error as I have no idea what I’m doing … code below (near to identical of @ih8gates

-- talk to HA
function ha_api(endpoint,payload)
-- endpoint like services/automation/trigger
-- whatever comes after api
-- payload like {"entity_id":"automation.garage_doors_trigger_lights"}
	local http = require("socket.http")
	local ltn12 = require("ltn12")

	local request_body = payload
	local response_body = {}

	b, c, h = http.request {
	  url = 'http://192.168.1.39:8123/api/' .. endpoint,
          method = 'POST',
	  headers = {
	    ["Content-Type"] =  "application/json",
	    ["Content-Length"] = string.len(request_body),
            ["Authorization"] = "Bearer YOUR LONGLIVED TOKEN GENERATED BY HASS",
	    },
	  source = ltn12.source.string(request_body),
	  sink = ltn12.sink.table(response_body),
	}

end

Testing with below was also usefull:

http.timeout = 5 
local  body, code, headers, status = http.request {
  method = "POST",
  url = "http://192.168.1.39:8123/api/services/input_boolean/turn_on",
  headers = {
	    ["Content-Type"] =  "application/json",
            ["Authorization"] = "Bearer YOUR LONGLIVED TOKEN GENERATED BY HASS"",
            ["Payload"] = '{"entity_id":"input_boolean.rfiddisarm"}'
            }
}

Hi @Tyfoon, I’ve been scratching my head over this. I’m trying to send HA events from Vera using the long-lived access token. My goal is to use my Wallmote like @maddox did. I’m guessing the first part of your code goes to the LUA box in Vera (Apps->Develop Apps->Test Luup code(Lua)), correct? The second part then goes to the Luup box in the scene creation page? I’m no programmer so I’m a bit lost here. Still can’t see the events in HA nor control any devices like you do.

The code goes into Apps->Develop Apps->edit startup LUA

Then under scenes, also execute LUA:
ha_api("services/input_boolean/turn_on", '{"entity_id":"input_boolean.rfidarm"}')

It’s working great now. I can see the events sent through Vera scenes. Thanks so much!

Is there anything special about the syntax for

[“Authorization”] = “Bearer YOUR LONGLIVED TOKEN GENERATED BY HASS”

I keep getting an error log message and the service does not call… :

— LUA TEST CODE:

http.timeout = 15 
local  body, code, headers, status = http.request {
  method = "POST",
  url = "http://192.168.10.55:8123/api/services/input_boolean/turn_on",
  headers = {
	    ["Content-Type"] =  "application/json",
        ["Authorization"] = "<<TOKEN>>",
        ["Payload"] = '{"entity_id":"input_boolean.panel_button1"}'
    }
}

----- CONFIGURATION.YAML


input_boolean:
  panel_button1:
    name: "Button 1"
    initial:  off
    icon: mdi:switch

my error log

2020-04-02 23:28:58 DEBUG (MainThread) [homeassistant.components.http.auth] Authenticated 192.168.10.221 for /api/error_log using bearer token
2020-04-02 23:28:58 DEBUG (MainThread) [homeassistant.components.http.view] Serving /api/error_log to 192.168.10.221 (auth: True)

Could it be that you miss the word ‘Bearer’ in front of the “TOKEN”?

I’m still struggling to get this to work. I’ve tried two options, both only with LUA code in the scene (nothing in startup LUA, as I see a reference to that a few post ago):

  1. Creating a scene which triggers an input Boolean:

execute the following Luup in scene:

local http = require "socket.http"
http.timeout = 5 
local  body, code, headers, status = http.request {
  method = "POST",
  url = "http://<<My HASS IP>>:8123/api/services/input_boolean/turn_on",
  headers = {
	    ["Content-Type"] =  "application/json",
        ["Authorization"] = "Bearer <<My Token>>",
        ["Payload"] = '{"entity_id":"input_boolean.dummy_switch_1"}'
    }
}
  1. Creating a scene which creates an event:

execute the following Luup in scene:

local http = require "socket.http"
http.timeout = 5 
local  body, code, headers, status = http.request {
  method = "POST",
  url = "http://<<My HASS IP>>:8123/api/events/wallmote_button_1",
  headers = {["Authorization"] = "Bearer <<My Token>>"}
}

Both options give me no luck, I don’t see anything in the HA Log, and the input Boolean is not triggered. What am I missing here. any help would be greatly appreciated.