def flatten_port_dicts(dicts):
    """
    Input:
        dicts (dict): embedded state dictionaries with the {'port_id': {'state_id': state_value}}

    Return:
        dict: flattened dictionary with {'state_id_port_id': value}
    """
    merge = {}
    for port, states_dict in dicts.items():
        for state, value in states_dict.items():
            merge.update({state + '_' + port: value})
    return merge