Issues with input_slider together with in automation

I’m trying to use an input_slider together with automation to create a custom MQTT dimmer.

This is the code:

#MQTT DIMMER 1
automation 1:
  alias: 'MQTT Input Slider Dimmer1'
  trigger:
    platform: state
    entity_id: input_slider.slider1
  action:
    service: mqtt.publish
    data_template:
      topic: kitchen/dimmer1/brightness/set
      payload: {{ states.trigger.new_state }}

I have tried several ways for setting payload, but nothing works.

payload: {{ trigger.new_state }}

payload: {{ states.input_slider.slider1 }}

payload: {{ states(trigger.new_state) }}

payload: {{ states(input_slider.slider1) }}

This is the error I get:
> Config directory: /home/pi/.homeassistant/
> Process Process-1:
> Traceback (most recent call last):
> File “/usr/lib/python3.4/multiprocessing/process.py”, line 254, in _bootstrap
> self.run()
> File “/usr/lib/python3.4/multiprocessing/process.py”, line 93, in run
> self._target(*self._args, **self._kwargs)
> File “/usr/local/lib/python3.4/dist-packages/homeassistant/main.py”, line 245, in setup_and_run_hass
> skip_pip=args.skip_pip, log_rotate_days=args.log_rotate_days)
> File “/usr/local/lib/python3.4/dist-packages/homeassistant/bootstrap.py”, line 299, in from_config_file
> config_dict = config_util.load_yaml_config_file(config_path)
> File “/usr/local/lib/python3.4/dist-packages/homeassistant/config.py”, line 149, in load_yaml_config_file
> conf_dict = load_yaml(config_path)
> File “/usr/local/lib/python3.4/dist-packages/homeassistant/util/yaml.py”, line 31, in load_yaml
> return yaml.load(conf_file, Loader=SafeLineLoader) or {}
> File “/usr/local/lib/python3.4/dist-packages/yaml/init.py”, line 72, in load
> return loader.get_single_data()
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 37, in get_single_data
> return self.construct_document(node)
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 41, in construct_document
> data = self.construct_object(node)
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 86, in construct_object
> data = constructor(self, node)
> File “/usr/local/lib/python3.4/dist-packages/homeassistant/util/yaml.py”, line 50, in _ordered_dict
> nodes = loader.construct_pairs(node)
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 141, in construct_pairs
> value = self.construct_object(value_node, deep=deep)
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 86, in construct_object
> data = constructor(self, node)
> File “/usr/local/lib/python3.4/dist-packages/homeassistant/util/yaml.py”, line 50, in _ordered_dict
> nodes = loader.construct_pairs(node)
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 141, in construct_pairs
> value = self.construct_object(value_node, deep=deep)
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 86, in construct_object
> data = constructor(self, node)
> File “/usr/local/lib/python3.4/dist-packages/homeassistant/util/yaml.py”, line 50, in _ordered_dict
> nodes = loader.construct_pairs(node)
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 141, in construct_pairs
> value = self.construct_object(value_node, deep=deep)
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 86, in construct_object
> data = constructor(self, node)
> File “/usr/local/lib/python3.4/dist-packages/homeassistant/util/yaml.py”, line 50, in _ordered_dict
> nodes = loader.construct_pairs(node)
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 141, in construct_pairs
> value = self.construct_object(value_node, deep=deep)
> File “/usr/local/lib/python3.4/dist-packages/yaml/constructor.py”, line 86, in construct_object
> data = constructor(self, node)
> File “/usr/local/lib/python3.4/dist-packages/homeassistant/util/yaml.py”, line 58, in _ordered_dict
> if key in seen:
> TypeError: unhashable type: ‘OrderedDict’

Anyone know what to do?

(The reason I dont use the built-in MQTT-dimmer in HA, is that whenever the brightness-value is set - HA is also setting payload to “on”, which in my setup is the same as brightness=255.)

Grateful for any help!!

Looks like I’ve run into the same problem.

automation:
- alias: "Pool change mode"
  trigger:
    platform: state
    entity_id: input_select.pool_mode
  action:
    service: "mqtt.publish"
    data_template:
      topic: "home/pool/mode"
      payload: {{ trigger.to_state }}`

Error thrown…

Config directory: /config
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/homeassistant/__main__.py", line 395, in 
    sys.exit(main())
  File "/usr/src/app/homeassistant/__main__.py", line 387, in main
    exit_code = setup_and_run_hass(config_dir, args)
  File "/usr/src/app/homeassistant/__main__.py", line 293, in setup_and_run_hass
    log_rotate_days=args.log_rotate_days)
  File "/usr/src/app/homeassistant/bootstrap.py", line 299, in from_config_file
    config_dict = config_util.load_yaml_config_file(config_path)
  File "/usr/src/app/homeassistant/config.py", line 149, in load_yaml_config_file
    conf_dict = load_yaml(config_path)
  File "/usr/src/app/homeassistant/util/yaml.py", line 32, in load_yaml
    return yaml.load(conf_file, Loader=SafeLineLoader) or {}
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/__init__.py", line 72, in load
    return loader.get_single_data()
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 37, in get_single_data
    return self.construct_document(node)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 41, in construct_document
    data = self.construct_object(node)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/usr/src/app/homeassistant/util/yaml.py", line 89, in _ordered_dict
    nodes = loader.construct_pairs(node)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 141, in construct_pairs
    value = self.construct_object(value_node, deep=deep)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/usr/src/app/homeassistant/util/yaml.py", line 45, in _include_yaml
    return load_yaml(fname)
  File "/usr/src/app/homeassistant/util/yaml.py", line 32, in load_yaml
    return yaml.load(conf_file, Loader=SafeLineLoader) or {}
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/__init__.py", line 72, in load
    return loader.get_single_data()
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 37, in get_single_data
    return self.construct_document(node)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 46, in construct_document
    for dummy in generator:
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 393, in construct_yaml_seq
    data.extend(self.construct_sequence(node))
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 116, in construct_sequence
    for child in node.value]
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 116, in 
    for child in node.value]
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/usr/src/app/homeassistant/util/yaml.py", line 89, in _ordered_dict
    nodes = loader.construct_pairs(node)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 141, in construct_pairs
    value = self.construct_object(value_node, deep=deep)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/usr/src/app/homeassistant/util/yaml.py", line 89, in _ordered_dict
    nodes = loader.construct_pairs(node)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 141, in construct_pairs
    value = self.construct_object(value_node, deep=deep)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/usr/src/app/homeassistant/util/yaml.py", line 89, in _ordered_dict
    nodes = loader.construct_pairs(node)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 141, in construct_pairs
    value = self.construct_object(value_node, deep=deep)
  File "/usr/local/lib/python3.4/site-packages/PyYAML-3.11-py3.4-linux-x86_64.egg/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/usr/src/app/homeassistant/util/yaml.py", line 97, in _ordered_dict
    if key in seen:
TypeError: unhashable type: 'OrderedDict'

Looks to be a formatting error. Below worked for me (note the single quotes).

- alias: "Pool change mode"
  trigger:
    platform: state
    entity_id: input_select.pool_mode
  action:
    service: "mqtt.publish"
    data_template:
      topic: "home/pool/mode"
      retain: "true"
      payload: '{{states("input_select.pool_mode")}}'
1 Like

Cool, thanks! Will try this!

Got this to work finally:

Input slider code:

input_slider:
  dimmer_dm1_1:
    name: Dimmer
    initial: 5
    min: 5
    max: 95
    step: 5

Automation code:

automation 6:
  alias: 'DimmerVardagsrumSliderSet'
  trigger:
    platform: state
    entity_id: input_slider.dimmer_dm1_1
  action:
    service: "mqtt.publish"
    data_template:
      topic: "sumpan/kitchen/dimmers/dm1/brightness/set"
      retain: "false"
      payload: '{{states("input_slider.dimmer_dm1_1")}}'

I’m not too familiar with MQTT and how it is used. Can you explain. That part of the logic? I use cloudqtt.

MQTT is a lightweight communication protocol. Logically it is a little bit like twitter. Each message contain a topic (like a twitter hashtag) and a payload (the message). You need to have a MQTT-broker (i use mosquitto) that receives messages from a node and broadcast it to all other connected nodes. You define what topics each node subscribes to. See http://www.hivemq.com/mqtt/ for a more detailed explanation.

In my setup, I have an Arduino Uno that controls a relay and a dimmer module (http://www.ebay.com/itm/2pcs-3BIT-AC-LED-Light-Dimmer-Module-Arduino-Raspberry-50Hz-60Hz-/121911897888). The Uno subcribes to MQTT control messages that tells the UNO if the relay should be on or off, and what dimming level the dimmer should be set to. I can send control messages from both Home Assistant (using the input_slider above) and a remote control that I have built using a NodeMCU connected to some physical switches.

1 Like

Thank you! I appreciate the explanation, I’m trying to learn as much as I can!

1 Like