Haswitch clarification

I have a problem with Haswitch in HADashboard.
I need a simple on\off button in Hadashboard connected to a switch in HA but I cannot get it to work.
My switches.yaml configuration is this:

- platform: command_line
      command_on: mosquitto_pub -V mqttv311 -h IP_ADDRESS -t "CMD/ON" -m ""
      command_off: mosquitto_pub -V mqttv311 -h IP_ADDRESS -t "CMD/OFF" -m ""
      value_template: '{{ value == "1" }}'

and it is working on the HA panel without any problems.
So I wanted to add same “button” in dashboard and I added this in main.erb:

<div data-id="kitchen_led_strip" data-view="Haswitch" data-icon="sliders" data-title="LED" data-color="#FF0000"></div>

After pressed, it changes its status but does nothing at all. Looking in thin.log I can see

2017-01-29 11:05:48 - NoMethodError - undefined method `strip' for #<Hash:0x7823ce68>:
	/home/purcazzo/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/http/header.rb:18:in `block in initialize_http_header'
	/home/purcazzo/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/http/header.rb:16:in `each'
	/home/purcazzo/.rbenv/versions/2.3.1/lib/ruby/2.3.0/net/http/header.rb:16:in `initialize_http_header'
	/home/purcazzo/hadashboard/jobs/homeassistant.rb:22:in `ha_api'
	/home/purcazzo/hadashboard/jobs/homeassistant.rb:45:in `block in <top (required)>'

Am I missing something?..

Hmm, if I had to guess I would say there is a problem with your $ha_apikey variable in ha_conf.rb.

Thanks for response!
Uhm…on the same dashboard I have two Hasensor and a customized Google News widget working so I don’t think is related to ha_apikey…unless I’m missing something, of course :sweat_smile:

Can you verify what is at line 22 of your homeassistant.rb please? Just copy and paste the line of code.

Sure!..here it is

request.initialize_http_header({"x-ha-access" => $ha_apikey, 'Content-Type' =>'application/json'})

(sorry for late response)

OK, can you post your ha_config.rb please.

of course:

$ha_url = ""
$ha_apikey =

$news_feeds = {
  "Traffic" => "http://api.sr.se/api/rss/traffic/2863",
  "News" => "https://news.google.it/news?cf=all&hl=it&pz=1&ned=it&output=rss",
  "Google" => "https://news.google.it/?output=rss"

apikey is empty (not using it),I will add it when needed

Mmm, can you try setting it to "" at least.

Ok, I will try when at home (right now I am at work) and I’ll let you know!

It works! Thank you for your help @aimc!

1 Like